Fix typos and potential leaks in ECC as well
parent
3444d6678a
commit
78a0dcb687
|
@ -193,7 +193,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt,
|
||||||
* Output key(s) to file(s)
|
* Output key(s) to file(s)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* set up the file name outut beffer */
|
/* set up the file name output buffer */
|
||||||
fOutNameBuf = (char*)XMALLOC(fNameSz + fExtSz, HEAP_HINT,
|
fOutNameBuf = (char*)XMALLOC(fNameSz + fExtSz, HEAP_HINT,
|
||||||
DYNAMIC_TYPE_TMP_BUFFER);
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (fOutNameBuf == NULL)
|
if (fOutNameBuf == NULL)
|
||||||
|
@ -217,18 +217,21 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt,
|
||||||
|
|
||||||
derBufSz = wc_EccPrivateKeyToDer(&key, derBuf, maxDerBufSz);
|
derBufSz = wc_EccPrivateKeyToDer(&key, derBuf, maxDerBufSz);
|
||||||
if (derBufSz < 0) {
|
if (derBufSz < 0) {
|
||||||
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return derBufSz;
|
return derBufSz;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = fopen(fOutNameBuf, "wb");
|
file = fopen(fOutNameBuf, "wb");
|
||||||
if (file == XBADFILE) {
|
if (file == XBADFILE) {
|
||||||
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return OUTPUT_FILE_ERROR;
|
return OUTPUT_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (int)fwrite(derBuf, 1, derBufSz, file);
|
ret = (int)fwrite(derBuf, 1, derBufSz, file);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return OUTPUT_FILE_ERROR;
|
return OUTPUT_FILE_ERROR;
|
||||||
|
@ -245,6 +248,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt,
|
||||||
|
|
||||||
derBufSz = wc_EccPublicKeyToDer(&key, derBuf, maxDerBufSz, 1);
|
derBufSz = wc_EccPublicKeyToDer(&key, derBuf, maxDerBufSz, 1);
|
||||||
if (derBufSz < 0) {
|
if (derBufSz < 0) {
|
||||||
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return derBufSz;
|
return derBufSz;
|
||||||
}
|
}
|
||||||
|
@ -252,6 +256,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt,
|
||||||
file = fopen(fOutNameBuf, "wb");
|
file = fopen(fOutNameBuf, "wb");
|
||||||
if (file == XBADFILE) {
|
if (file == XBADFILE) {
|
||||||
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return OUTPUT_FILE_ERROR;
|
return OUTPUT_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,6 +264,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt,
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return OUTPUT_FILE_ERROR;
|
return OUTPUT_FILE_ERROR;
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -266,6 +272,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt,
|
||||||
default:
|
default:
|
||||||
printf("Invalid directive\n");
|
printf("Invalid directive\n");
|
||||||
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +340,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int
|
||||||
* Output key(s) to file(s)
|
* Output key(s) to file(s)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* set up the file name outut beffer */
|
/* set up the file name output buffer */
|
||||||
fOutNameBuf = (char*)XMALLOC(fNameSz + fExtSz, HEAP_HINT,
|
fOutNameBuf = (char*)XMALLOC(fNameSz + fExtSz, HEAP_HINT,
|
||||||
DYNAMIC_TYPE_TMP_BUFFER);
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (fOutNameBuf == NULL)
|
if (fOutNameBuf == NULL)
|
||||||
|
|
Loading…
Reference in New Issue