Merge pull request #121 from kaleb-himes/MEM_LEAK_FIX

Spotted obvious potential leak when reviewing function for support case
pull/124/head
JacobBarthelmeh 2019-02-04 10:34:59 -07:00 committed by GitHub
commit b240a32b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -357,18 +357,21 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int
derBufSz = wc_RsaKeyToDer(&key, derBuf, maxDerBufSz);
if (derBufSz < 0) {
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return derBufSz;
}
file = fopen(fOutNameBuf, "wb");
if (file == XBADFILE) {
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return OUTPUT_FILE_ERROR;
}
ret = (int)fwrite(derBuf, 1, derBufSz, file);
if (ret <= 0) {
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
fclose(file);
return OUTPUT_FILE_ERROR;
@ -385,6 +388,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int
derBufSz = wc_RsaKeyToPublicDer(&key, derBuf, maxDerBufSz);
if (derBufSz < 0) {
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return derBufSz;
}
@ -392,6 +396,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int
file = fopen(fOutNameBuf, "wb");
if (file == XBADFILE) {
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return OUTPUT_FILE_ERROR;
}
@ -399,6 +404,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int
if (ret <= 0) {
fclose(file);
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return OUTPUT_FILE_ERROR;
}
fclose(file);
@ -406,6 +412,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int
default:
printf("Invalid directive\n");
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return BAD_FUNC_ARG;
}