create buffer with structure copy and set fd after close

This commit is contained in:
Jacob Barthelmeh
2018-08-03 16:46:15 -06:00
parent 7726786998
commit 30e787b10c
2 changed files with 12 additions and 0 deletions

View File

@ -176,10 +176,20 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
}
XMEMCPY(dst, src, sizeof(wc_Sha256));
#ifdef WOLFSSL_AFALG_HASH_KEEP
dst->msg = (byte*)XMALLOC(src->len, dst->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (dst->msg == NULL) {
return MEMORY_E;
}
XMEMCPY(dst->msg, src->msg, src->len);
#endif
dst->rdFd = accept(src->rdFd, NULL, 0);
dst->alFd = accept(src->alFd, NULL, 0);
if (dst->rdFd == -1 || dst->alFd == -1) {
wc_Sha256Free(dst);
return -1;
}

View File

@ -2750,9 +2750,11 @@ void wc_Sha256Free(wc_Sha256* sha256)
#if defined(WOLFSSL_AFALG_HASH)
if (sha256->alFd > 0) {
close(sha256->alFd);
sha256->alFd = -1; /* avoid possible double close on socket */
}
if (sha256->rdFd > 0) {
close(sha256->rdFd);
sha256->rdFd = -1; /* avoid possible double close on socket */
}
#if defined(WOLFSSL_AFALG_HASH_KEEP)