Skip to content

Commit

Permalink
Fix: replace free() with dealloc()
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxwolf authored Jul 17, 2016
2 parents f43f17d + 03107ec commit 8361f38
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 72 deletions.
24 changes: 12 additions & 12 deletions src/jws.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static bool _cjose_jws_build_sig_ps256(
retval = true;

_cjose_jws_build_sig_ps256_cleanup:
free(em);
cjose_get_dealloc()(em);

return retval;
}
Expand Down Expand Up @@ -596,14 +596,14 @@ void cjose_jws_release(cjose_jws_t *jws)
json_decref(jws->hdr);
}

free(jws->hdr_b64u);
free(jws->dat);
free(jws->dat_b64u);
free(jws->dig);
free(jws->sig);
free(jws->sig_b64u);
free(jws->cser);
free(jws);
cjose_get_dealloc()(jws->hdr_b64u);
cjose_get_dealloc()(jws->dat);
cjose_get_dealloc()(jws->dat_b64u);
cjose_get_dealloc()(jws->dig);
cjose_get_dealloc()(jws->sig);
cjose_get_dealloc()(jws->sig_b64u);
cjose_get_dealloc()(jws->cser);
cjose_get_dealloc()(jws);
}


Expand Down Expand Up @@ -707,7 +707,7 @@ cjose_jws_t *cjose_jws_import(

// deserialize JSON header
jws->hdr = json_loadb((const char *)hdr_str, len, 0, NULL);
free(hdr_str);
cjose_get_dealloc()(hdr_str);
if (NULL == jws->hdr)
{
CJOSE_ERROR(err, CJOSE_ERR_INVALID_ARG);
Expand Down Expand Up @@ -801,7 +801,7 @@ static bool _cjose_jws_verify_sig_ps256(
retval = true;

_cjose_jws_verify_sig_ps256_cleanup:
free(em);
cjose_get_dealloc()(em);

return retval;
}
Expand Down Expand Up @@ -867,7 +867,7 @@ static bool _cjose_jws_verify_sig_rs256(
retval = true;

_cjose_jws_verify_sig_rs256_cleanup:
free(dig);
cjose_get_dealloc()(dig);

return retval;
}
Expand Down
60 changes: 31 additions & 29 deletions test/check_base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <check.h>
#include <cjose/base64.h>
#include <cjose/util.h>

START_TEST(test_cjose_base64_encode)
{
Expand All @@ -17,7 +18,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(16, outlen);
ck_assert_str_eq("aGVsbG8gdGhlcmU=", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"A B C D E F ";
inlen = 12;
Expand All @@ -26,7 +27,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(16, outlen);
ck_assert_str_eq("QSBCIEMgRCBFIEYg", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"hello\xfethere";
inlen = 11;
Expand All @@ -35,7 +36,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(16, outlen);
ck_assert_str_eq("aGVsbG/+dGhlcmU=", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"\xfe";
inlen = 1;
Expand All @@ -44,7 +45,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(4, outlen);
ck_assert_str_eq("/g==", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"\x01\x02";
inlen = 2;
Expand All @@ -53,7 +54,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(4, outlen);
ck_assert_str_eq("AQI=", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"\x01";
inlen = 1;
Expand All @@ -62,7 +63,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(4, outlen);
ck_assert_str_eq("AQ==", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"";
inlen = 0;
Expand All @@ -71,7 +72,7 @@ START_TEST(test_cjose_base64_encode)
ck_assert(cjose_base64_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(0, outlen);
ck_assert_str_eq("", output);
free(output);
cjose_get_dealloc()(output);

// input may be NULL iff inlen is 0
input = NULL;
Expand Down Expand Up @@ -116,7 +117,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(15, outlen);
ck_assert_str_eq("aGVsbG8gdGhlcmU", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"A B C D E F ";
inlen = 12;
Expand All @@ -125,7 +126,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(16, outlen);
ck_assert_str_eq("QSBCIEMgRCBFIEYg", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"hello\xfethere";
inlen = 11;
Expand All @@ -134,7 +135,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(15, outlen);
ck_assert_str_eq("aGVsbG_-dGhlcmU", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"\xfe";
inlen = 1;
Expand All @@ -143,7 +144,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(2, outlen);
ck_assert_str_eq("_g", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"\x01\x02";
inlen = 2;
Expand All @@ -152,7 +153,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(3, outlen);
ck_assert_str_eq("AQI", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"\x01";
inlen = 1;
Expand All @@ -161,7 +162,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(2, outlen);
ck_assert_str_eq("AQ", output);
free(output);
cjose_get_dealloc()(output);

input = (uint8_t *)"";
inlen = 0;
Expand All @@ -170,7 +171,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(0, outlen);
ck_assert_str_eq("", output);
free(output);
cjose_get_dealloc()(output);

// input may be NULL off inlen is 0
input = NULL;
Expand All @@ -180,6 +181,7 @@ START_TEST(test_cjose_base64url_encode)
ck_assert(cjose_base64url_encode(input, inlen, &output, &outlen, &err));
ck_assert_str_eq("", output);
ck_assert(0 == outlen);
cjose_get_dealloc()(output);

// invalid arguments -- output == NULL
input = "valid";
Expand Down Expand Up @@ -217,7 +219,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(11, outlen);
ck_assert_bin_eq((uint8_t *)"hello there", output, 11);
free(output);
cjose_get_dealloc()(output);

input = "QSBCIEMgRCBFIEYg";
inlen = 16;
Expand All @@ -226,7 +228,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(12, outlen);
ck_assert_bin_eq((uint8_t *)"A B C D E F ", output, 12);
free(output);
cjose_get_dealloc()(output);

input = "aGVsbG/+dGhlcmU=";
inlen = 16;
Expand All @@ -235,7 +237,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(11, outlen);
ck_assert_bin_eq((uint8_t *)"hello\xfethere", output, 11);
free(output);
cjose_get_dealloc()(output);

input = "/g==";
inlen = 4;
Expand All @@ -244,7 +246,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(1, outlen);
ck_assert_bin_eq((uint8_t *)"\xfe", output, 1);
free(output);
cjose_get_dealloc()(output);

input = "AQI=";
inlen = 4;
Expand All @@ -253,7 +255,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(2, outlen);
ck_assert_bin_eq((uint8_t *)"\x01\x02", output, 2);
free(output);
cjose_get_dealloc()(output);

input = "AQ==";
inlen = 4;
Expand All @@ -262,7 +264,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(1, outlen);
ck_assert_bin_eq((uint8_t *)"\x01", output, 1);
free(output);
cjose_get_dealloc()(output);

input = "";
inlen = 0;
Expand All @@ -271,7 +273,7 @@ START_TEST(test_cjose_base64_decode)
ck_assert(cjose_base64_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(0, outlen);
ck_assert_bin_eq((uint8_t *)"", output, 0);
free(output);
cjose_get_dealloc()(output);

// invalid arguments -- input == NULL
input = NULL;
Expand Down Expand Up @@ -329,7 +331,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(11, outlen);
ck_assert_bin_eq((uint8_t *)"hello there", output, 11);
free(output);
cjose_get_dealloc()(output);

input = "QSBCIEMgRCBFIEYg";
inlen = 16;
Expand All @@ -338,7 +340,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(12, outlen);
ck_assert_bin_eq((uint8_t *)"A B C D E F ", output, 12);
free(output);
cjose_get_dealloc()(output);

input = "aGVsbG_-dGhlcmU";
inlen = 15;
Expand All @@ -347,7 +349,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(11, outlen);
ck_assert_bin_eq((uint8_t *)"hello\xfethere", output, 11);
free(output);
cjose_get_dealloc()(output);

input = "_g";
inlen = 2;
Expand All @@ -356,7 +358,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(1, outlen);
ck_assert_bin_eq((uint8_t *)"\xfe", output, 1);
free(output);
cjose_get_dealloc()(output);

input = "AQI";
inlen = 3;
Expand All @@ -365,7 +367,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(2, outlen);
ck_assert_bin_eq((uint8_t *)"\x01\x02", output, 2);
free(output);
cjose_get_dealloc()(output);

input = "AQ";
inlen = 2;
Expand All @@ -374,7 +376,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(1, outlen);
ck_assert_bin_eq((uint8_t *)"\x01", output, 1);
free(output);
cjose_get_dealloc()(output);

input = "";
inlen = 0;
Expand All @@ -383,7 +385,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(0, outlen);
ck_assert_bin_eq((uint8_t *)"", output, 0);
free(output);
cjose_get_dealloc()(output);

input = "valids";
inlen = 6;
Expand All @@ -392,7 +394,7 @@ START_TEST(test_cjose_base64url_decode)
ck_assert(cjose_base64url_decode(input, inlen, &output, &outlen, &err));
ck_assert_int_eq(4, outlen);
ck_assert_bin_eq((uint8_t *)"\xbd\xa9\x62\x76", output, 4);
free(output);
cjose_get_dealloc()(output);

// invalid arguments -- input == NULL
input = NULL;
Expand Down
6 changes: 4 additions & 2 deletions test/check_jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ START_TEST(test_cjose_jwe_node_jose_encrypt_self_decrypt)
strncmp(PLAINTEXT, plain2, plain2_len) == 0,
"decrypted plaintext does not match encrypted plaintext");

cjose_get_dealloc()(plain2);
cjose_jwk_release(jwk);
cjose_jwe_release(jwe);
}
Expand Down Expand Up @@ -152,11 +153,12 @@ static void _self_encrypt_self_decrypt_with_key(
strncmp(plain1, plain2, plain2_len) == 0,
"decrypted plaintext does not match encrypted plaintext");

cjose_get_dealloc()(plain2);
cjose_header_release(hdr);
cjose_jwe_release(jwe1);
cjose_jwe_release(jwe2);
cjose_jwk_release(jwk);
free(compact);
cjose_get_dealloc()(compact);
}


Expand Down Expand Up @@ -449,7 +451,7 @@ START_TEST(test_cjose_jwe_import_export_compare)

cjose_jwk_release(jwk);
cjose_jwe_release(jwe);
free(cser);
cjose_get_dealloc()(cser);
}
END_TEST

Expand Down
Loading

0 comments on commit 8361f38

Please sign in to comment.