Commit cef21e07 authored by Vasil Velichkov's avatar Vasil Velichkov Committed by Lev Walkin

Fix several memory leaks in the tests

parent 5532a1d6
......@@ -45,6 +45,8 @@ check_xer(e_Enum2 eval, char *xer_string) {
sprintf(buf2, "<Enum2>%s</Enum2>", xer_string);
printf("%d -> %s == %s\n", eval, buf, buf2);
assert(0 == strcmp(buf, buf2));
ASN_STRUCT_FREE(asn_DEF_Enum2, e);
}
int
......
......@@ -249,6 +249,7 @@ process_XER_data(const char *fname, enum expectation expectation, unsigned char
/* Save and re-load as PER */
save_object_as(st, expectation, AS_PER);
ASN_STRUCT_FREE(asn_DEF_PDU, st);
if(expectation == EXP_PER_NOCOMP)
return; /* Already checked */
st = load_object_from("buffer", expectation, buf, buf_offset, AS_PER);
......
......@@ -251,6 +251,8 @@ process_XER_data(const char *fname, enum expectation expectation, unsigned char
/* Save and re-load as PER */
save_object_as(st, expectation, AS_PER);
ASN_STRUCT_FREE(asn_DEF_PDU, st);
if(expectation == EXP_PER_NOCOMP)
return; /* Already checked */
st = load_object_from("buffer", expectation, buf, buf_offset, AS_PER);
......
......@@ -150,6 +150,7 @@ load_object_from(const char *fname, unsigned char *fbuf, size_t size, enum encty
rval.consumed /= 8;
if(mustfail) {
fprintf(stderr, "-> (this was expected failure)\n");
ASN_STRUCT_FREE(asn_DEF_PDU, st);
return 0;
}
} else {
......@@ -167,6 +168,7 @@ load_object_from(const char *fname, unsigned char *fbuf, size_t size, enum encty
if((mustfail?1:0) == (rval.code == RC_FAIL)) {
if(mustfail) {
fprintf(stderr, "-> (this was expected failure)\n");
ASN_STRUCT_FREE(asn_DEF_PDU, st);
return 0;
}
} else {
......@@ -246,6 +248,7 @@ compare_with_data_out(const char *fname, void *datap, size_t size) {
FILE *f;
char lastChar;
int mustfail, compare;
PDU_t *st;
sprintf(outName, SRCDIR_S "/data-126/%s", fname);
strcpy(outName + strlen(outName) - 3, ".out");
......@@ -268,7 +271,8 @@ compare_with_data_out(const char *fname, void *datap, size_t size) {
fclose(f);
fprintf(stderr, "Trying to decode [%s]\n", outName);
load_object_from(outName, fbuf, rd, AS_PER, mustfail);
st = load_object_from(outName, fbuf, rd, AS_PER, mustfail);
ASN_STRUCT_FREE(asn_DEF_PDU, st);
if(mustfail) return;
if(compare) {
......@@ -291,6 +295,7 @@ process_XER_data(const char *fname, unsigned char *fbuf, size_t size) {
/* Save and re-load as PER */
save_object_as(st, AS_PER);
ASN_STRUCT_FREE(asn_DEF_PDU, st);
compare_with_data_out(fname, buf, buf_offset);
st = load_object_from("buffer", buf, buf_offset, AS_PER, 0);
assert(st);
......
......@@ -42,6 +42,8 @@ verify(int testNo, T_t *ti) {
xer_fprint(stderr, &asn_DEF_T, ti);
xer_fprint(stderr, &asn_DEF_T, to);
ASN_STRUCT_FREE(asn_DEF_T, to);
}
int main() {
......
......@@ -55,5 +55,6 @@ main() {
|| (pd.nboff == 16 && pd.buffer == &po.tmpspace[0]));
assert(pd.nboff + pd.nbits == 16);
ASN_STRUCT_FREE(asn_DEF_T, t2);
return 0;
}
......@@ -36,6 +36,8 @@ verify(int testNo, T_t *ti) {
xer_fprint(stderr, &asn_DEF_T, ti);
xer_fprint(stderr, &asn_DEF_T, to);
ASN_STRUCT_FREE(asn_DEF_T, to);
}
int main() {
......
......@@ -36,6 +36,8 @@ int main() {
return 1;
}
ASN_STRUCT_RESET(asn_DEF_T, &source);
ASN_STRUCT_FREE(asn_DEF_T, decoded);
return 0;
}
......@@ -139,6 +139,8 @@ check_sequence(uint8_t *in, size_t in_size, uint8_t *expected,
buf2_pos = 0;
erval = der_encode(&asn_DEF_DefaultSequence, tp, buf2_fill, 0);
compare_encoding(&erval, expected, expected_size, buf2);
ASN_STRUCT_RESET(asn_DEF_DefaultSequence, tp);
}
static void
......@@ -160,6 +162,7 @@ check_set(uint8_t *in, size_t in_size, uint8_t *expected,
buf2_pos = 0;
erval = der_encode(&asn_DEF_DefaultSet, tp, buf2_fill, 0);
compare_encoding(&erval, expected, expected_size, buf2);
ASN_STRUCT_RESET(asn_DEF_DefaultSet, tp);
}
int
......
......@@ -79,6 +79,7 @@ check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
);
}
assert(rval.consumed <= (size_t)consumed);
ASN_STRUCT_RESET(asn_DEF_T1, tp);
return;
}
......@@ -113,6 +114,8 @@ check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
ret = xer_fprint(stderr, &asn_DEF_T1, tp);
assert(ret == 0);
fprintf(stderr, "=== EOF ===\n");
ASN_STRUCT_RESET(asn_DEF_T1, tp);
}
static void
......
......@@ -58,6 +58,8 @@ check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
}
assert(rval.consumed <= consumed);
}
ASN_STRUCT_RESET(asn_DEF_T, tp);
}
static void
......
......@@ -177,6 +177,7 @@ check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
}
assert(rval.consumed <= consumed);
}
ASN_STRUCT_RESET(asn_DEF_T, tp);
}
......@@ -212,6 +213,8 @@ check_xer(uint8_t *buf, uint8_t size, char *xer_sample) {
printf("[%s] vs [%s]\n", xer_buf, xer_sample);
assert(xer_off == xer_sample_len);
assert(memcmp(xer_buf, xer_sample, xer_off) == 0);
ASN_STRUCT_FREE(asn_DEF_T, tp);
}
static void
......
......@@ -124,6 +124,7 @@ check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
);
}
assert(rval.consumed <= consumed);
ASN_STRUCT_RESET(asn_DEF_Forest, &t);
return;
}
......@@ -173,6 +174,8 @@ check_xer(uint8_t *buf, uint8_t size, char *xer_sample) {
printf("[%s] vs [%s]\n", xer_buf, xer_sample);
assert(xer_off == xer_sample_len);
assert(memcmp(xer_buf, xer_sample, xer_off) == 0);
ASN_STRUCT_FREE(asn_DEF_Forest, tp);
}
......
......@@ -57,6 +57,7 @@ main(int ac, char **av) {
assert(swo->seqOfOpt != 0);
xer_fprint(stderr, &asn_DEF_SeqWithOptional, swo);
void *tmp = swo->seqOfOpt;
swo->seqOfOpt = 0;
erv = der_encode_to_buffer(&asn_DEF_SeqWithOptional,
......@@ -64,10 +65,15 @@ main(int ac, char **av) {
assert(erv.encoded > 0);
buf[erv.encoded] = '\0';
swo->seqOfOpt = tmp;
ASN_STRUCT_RESET(asn_DEF_SeqWithMandatory, &swm);
ASN_STRUCT_FREE(asn_DEF_SeqWithOptional, swo);
swo = 0;
drv = ber_decode(0, &asn_DEF_SeqWithMandatory, (void **)&swo,
buf, erv.encoded);
assert(drv.code != RC_OK);
ASN_STRUCT_FREE(asn_DEF_SeqWithOptional, swo);
swo = 0;
drv = ber_decode(0, &asn_DEF_SeqWithOptional, (void **)&swo,
buf, erv.encoded);
......@@ -76,6 +82,7 @@ main(int ac, char **av) {
assert(swo->seqOfOpt == 0);
xer_fprint(stderr, &asn_DEF_SeqWithOptional, swo);
ASN_STRUCT_FREE(asn_DEF_SeqWithOptional, swo);
printf("Finished\n");
......
......@@ -304,6 +304,8 @@ check_xer(uint8_t *data, uint8_t size, char *xer_sample) {
assert(er.encoded == (ssize_t)xer_off);
assert(xer_off == xer_sample_len);
assert(memcmp(xer_buf, xer_sample, xer_off) == 0);
ASN_STRUCT_FREE(asn_DEF_T, tp);
}
......
......@@ -31,6 +31,7 @@ check(uint8_t *buf, size_t size, size_t consumed) {
assert(rval.code == RC_OK);
assert(rval.consumed == consumed);
ASN_STRUCT_RESET(asn_DEF_T, tp);
}
int
......
......@@ -94,5 +94,7 @@ main() {
printf("OK\n");
ASN_STRUCT_RESET(asn_DEF_UserIdentifier, &user);
ASN_STRUCT_RESET(asn_DEF_UserIdentifier, &user_new);
return ret;
}
......@@ -109,7 +109,7 @@ main() {
* Test the T1 with primitive encoding.
*/
memset(&t1, 0, sizeof(t1));
memset(&t1_new, 0, sizeof(t1_new));
ASN_STRUCT_RESET(asn_DEF_T1, &t1_new);
t1.i = -112233;
t1.any.buf = test_any_buf2;
......@@ -123,6 +123,7 @@ main() {
assert(t1_new.i == -112233);
assert(t1_new.any.size == (ssize_t)sizeof(test_any_buf2));
assert(memcmp(t1_new.any.buf, test_any_buf2, sizeof(test_any_buf2)) == 0);
ASN_STRUCT_RESET(asn_DEF_T1, &t1_new);
/*
* Test the T2 empty sequence.
......@@ -146,8 +147,8 @@ main() {
/*
* Test the T2 sequence.
*/
memset(&t2, 0, sizeof(t2));
memset(&t2_new, 0, sizeof(t2_new));
ASN_STRUCT_RESET(asn_DEF_T2, &t2);
ASN_STRUCT_RESET(asn_DEF_T2, &t2_new);
t2.i = 332211;
t2.any = calloc(1, sizeof(*t2.any));
......@@ -166,8 +167,10 @@ main() {
/*
* Test the T2 sequence with primitive encoding.
*/
memset(&t2, 0, sizeof(t2));
memset(&t2_new, 0, sizeof(t2_new));
t2.any->buf = NULL;
t2.any->size = 0;
ASN_STRUCT_RESET(asn_DEF_T2, &t2);
ASN_STRUCT_RESET(asn_DEF_T2, &t2_new);
t2.i = 0;
t2.any = calloc(1, sizeof(*t2.any));
......@@ -188,7 +191,7 @@ main() {
*/
free(t2.any);
t2.any = 0;
memset(&t2_new, 0, sizeof(t2_new));
ASN_STRUCT_RESET(asn_DEF_T2, &t2_new);
save_object(&t2, td2);
ret = load_object(&t2_new, td2);
......
......@@ -95,6 +95,7 @@ check_2(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
}
assert(rval.consumed <= consumed);
}
ASN_STRUCT_RESET(*td, tp);
}
int
......
......@@ -190,6 +190,7 @@ process_XER_data(enum expectation expectation, unsigned char *fbuf, size_t size)
/* Save and re-load as DER */
save_object_as(st, ATS_DER);
ASN_STRUCT_FREE(asn_DEF_PDU, st);
st = load_object_from(expectation, buf, buf_offset, ATS_BER);
assert(st);
......
......@@ -184,6 +184,7 @@ process_XER_data(enum expectation expectation, unsigned char *fbuf, size_t size)
/* Save and re-load as DER */
save_object_as(st, ATS_DER);
ASN_STRUCT_FREE(asn_DEF_PDU, st);
st = load_object_from(expectation, buf, buf_offset, ATS_BER);
assert(st);
......
......@@ -70,6 +70,7 @@ verify(int testNo, T_t *ti) {
xer_fprint(stderr, &asn_DEF_T, ti);
xer_fprint(stderr, &asn_DEF_T, to);
ASN_STRUCT_FREE(asn_DEF_T, to);
}
static void
......@@ -95,36 +96,42 @@ int main() {
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
verify(1, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 1);
ul2i(&ti.unsigned42, 1);
l2i(&ti.signed33, 1);
l2i(&ti.signed33ext, 1);
verify(2, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 5000000000);
ul2i(&ti.unsigned42, 3153600000000);
l2i(&ti.signed33, 4000000000);
l2i(&ti.signed33ext, 4000000000);
verify(3, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, -1);
ul2i(&ti.unsigned42, 0);
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(4, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, -1);
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(5, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
l2i(&ti.signed33, -4000000000-1);
l2i(&ti.signed33ext, 0);
NO_encode(6, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
......@@ -132,30 +139,35 @@ int main() {
l2i(&ti.signed33ext, -4000000000-1);
assert(ti.signed33ext.size == 5);
verify(7, &ti); /* signed33ext is extensible */
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 5000000000 + 1);
ul2i(&ti.unsigned42, 0);
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(8, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 3153600000000 + 1);
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(9, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 5000000000 - 1);
ul2i(&ti.unsigned42, 3153600000000 - 1);
l2i(&ti.signed33, 4000000000 - 1);
l2i(&ti.signed33ext, 4000000000 - 1);
verify(10, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 4000000000 + 1);
verify(11, &ti);
ASN_STRUCT_RESET(asn_DEF_T, &ti);
return 0;
}
......
......@@ -38,7 +38,8 @@ int main() {
if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) {
return 1;
}
ASN_STRUCT_RESET(asn_DEF_T, &source);
ASN_STRUCT_FREE(asn_DEF_T, decoded);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment