Modify arg passing to retain NULL assignment

pull/26/head
kaleb-himes 2016-11-03 15:55:26 -06:00
parent e3678ee8cd
commit d1e818dd48
1 changed files with 15 additions and 13 deletions

View File

@ -8,7 +8,8 @@
#define HEAP_HINT NULL #define HEAP_HINT NULL
#define FOURK_SZ 4096 #define FOURK_SZ 4096
void free_things(byte* a, byte* b, byte* c, ecc_key* d, ecc_key* e, WC_RNG* f); void free_things(byte** a, byte** b, byte** c, ecc_key* d, ecc_key* e,
WC_RNG* f);
int main(void) { int main(void) {
@ -183,29 +184,30 @@ int main(void) {
goto success; goto success;
fail: fail:
free_things(derBuf, pemBuf, caKeyBuf, &caKey, &newKey, &rng); free_things(&derBuf, &pemBuf, &caKeyBuf, &caKey, &newKey, &rng);
printf("Failure code was %d\n", ret); printf("Failure code was %d\n", ret);
return -1; return -1;
success: success:
free_things(derBuf, pemBuf, caKeyBuf, &caKey, &newKey, &rng); free_things(&derBuf, &pemBuf, &caKeyBuf, &caKey, &newKey, &rng);
printf("Tests passed\n"); printf("Tests passed\n");
return 0; return 0;
} }
void free_things(byte* a, byte* b, byte* c, ecc_key* d, ecc_key* e, WC_RNG* f) void free_things(byte** a, byte** b, byte** c, ecc_key* d, ecc_key* e,
WC_RNG* f)
{ {
if (a != NULL) { if (*a != NULL) {
XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(*a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
a = NULL; *a = NULL;
} }
if (b != NULL) { if (*b != NULL) {
XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(*b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
b = NULL; *b = NULL;
} }
if (c != NULL) { if (*c != NULL) {
XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(*c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
c = NULL; *c = NULL;
} }
wc_ecc_free(d); wc_ecc_free(d);