Commit 229ad008 authored by Lev Walkin's avatar Lev Walkin

fixed memory leaks in test code

parent dcae9cea
......@@ -59,6 +59,7 @@ encode(time_t tloc, const char *expect, int force_gmt) {
} else {
assert(!expect);
}
ASN_STRUCT_FREE(asn_DEF_GeneralizedTime, gt);
}
#define RECODE(foo, bar) recode(__LINE__, foo, bar)
......
......@@ -54,6 +54,7 @@ check(uint8_t *buf, size_t size, long check_long, int check_ret) {
ret = asn_INTEGER2long(&val, &rlong2);
assert(ret == 0);
assert(rlong == rlong2);
ASN_STRUCT_RESET(asn_DEF_INTEGER, &val2);
}
shared_scratch_start = scratch;
......@@ -119,6 +120,7 @@ check_unsigned(uint8_t *buf, int size, unsigned long check_long, int check_ret)
ret = asn_INTEGER2ulong(&val, &rlong2);
assert(ret == 0);
assert(rlong == rlong2);
ASN_STRUCT_RESET(asn_DEF_INTEGER, &val2);
}
return;
......@@ -155,6 +157,7 @@ check_xer(int tofail, char *xmldata, long orig_value) {
if(rc.code != RC_OK) {
assert(tofail);
printf("\tfailed, as expected\n");
ASN_STRUCT_FREE(asn_DEF_INTEGER, st);
return;
}
assert(!tofail);
......
......@@ -48,6 +48,8 @@ check_impl(int lineno, enum encoding_type type, char *tagname, char *xmlbuf, cha
} else {
assert(rc.code != RC_OK);
}
ASN_STRUCT_FREE(*td, st);
}
static char buf[1024];
......@@ -78,6 +80,7 @@ encode(char *orig, char *encoded) {
printf("Orig: [%s], encoded: [%s], check [%s]\n",
orig, buf, encoded);
assert(strcmp(buf, encoded) == 0);
ASN_STRUCT_RESET(asn_DEF_OCTET_STRING, &os);
}
int
......
......@@ -48,6 +48,7 @@ check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const
lineno, control, size);
if(ret.code == code) {
fprintf(stderr, " (That was expected)\n");
ASN_STRUCT_FREE(asn_DEF_INTEGER, st);
return;
} else {
fprintf(
......@@ -76,6 +77,7 @@ check_decode(int lineno, enum asn_dec_rval_code_e code, intmax_t control, const
}
fprintf(stderr, "%d: Decode result %" PRIdMAX "\n", lineno, control);
ASN_STRUCT_FREE(asn_DEF_INTEGER, st);
}
static void
......
......@@ -57,6 +57,7 @@ check_OID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
printf(" }\n");
assert(alen == ck_len);
ASN_STRUCT_FREE(asn_DEF_OBJECT_IDENTIFIER, oid);
}
static void
......@@ -101,6 +102,7 @@ check_ROID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
assert(arcs[i] == (unsigned long)ck_buf[i]);
}
printf(" }\n");
ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, oid);
}
/*
......@@ -142,6 +144,7 @@ check_REGEN(int lineno, int *arcs, int acount) {
fprintf(stderr, "}\n");
}
ASN_STRUCT_RESET(asn_DEF_RELATIVE_OID, &oid);
}
/*
......@@ -183,7 +186,10 @@ check_REGEN_OID(int lineno, int *arcs, int acount) {
}
fprintf(stderr, "}\n");
}
ASN_STRUCT_RESET(asn_DEF_RELATIVE_OID, &oid);
}
static int
check_speed() {
uint8_t buf[] = { 0x80 | 7, 0x80 | 2, 0x80 | 3, 0x80 | 4, 13 };
......@@ -240,18 +246,18 @@ static void check_parse(const char *oid_txt, int retval) {
static void check_xer(int expect_arcs, char *xer) {
asn_dec_rval_t rc;
RELATIVE_OID_t *st = 0;
RELATIVE_OID_t **stp = &st;
long arcs[10];
int ret;
int i;
printf("[%s] => ", xer); fflush(stdout);
rc = asn_DEF_RELATIVE_OID.op->xer_decoder(0,
&asn_DEF_RELATIVE_OID, (void **)stp, "t",
&asn_DEF_RELATIVE_OID, (void **)&st, "t",
xer, strlen(xer));
if(expect_arcs == -1) {
if(rc.code != RC_OK) {
printf("-1\n");
ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st);
return;
}
}
......@@ -262,6 +268,7 @@ static void check_xer(int expect_arcs, char *xer) {
assert(ret < 10);
if(expect_arcs == -1) {
assert(ret == -1);
ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st);
return;
}
for(i = 0; i < ret; i++) {
......@@ -272,6 +279,7 @@ static void check_xer(int expect_arcs, char *xer) {
}
printf(": %d == %d\n", ret, expect_arcs);
assert(ret == expect_arcs);
ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st);
}
#define CHECK_OID(n) \
......
......@@ -112,6 +112,8 @@ check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound,
asn_INTEGER2long(reconstructed_st, &reconstructed_value);
assert(reconstructed_value == value);
}
ASN_STRUCT_RESET(asn_DEF_INTEGER, &st);
ASN_STRUCT_FREE(asn_DEF_INTEGER, reconstructed_st);
}
#define CHECK(u, v, l, r, b) \
......
......@@ -124,11 +124,9 @@ check_xer(int fuzzy, double orig_value) {
reconstr_lens[0] = 0;
reconstr_lens[1] = 0;
er = xer_encode(&asn_DEF_REAL, &st,
XER_F_BASIC, callback, 0);
er = xer_encode(&asn_DEF_REAL, &st, XER_F_BASIC, callback, 0);
assert(er.encoded == reconstr_lens[0]);
er = xer_encode(&asn_DEF_REAL, &st,
XER_F_CANONICAL, callback, (void *)1);
er = xer_encode(&asn_DEF_REAL, &st, XER_F_CANONICAL, callback, (void *)1);
assert(er.encoded == reconstr_lens[1]);
reconstructed[0][reconstr_lens[0]] = 0;
reconstructed[1][reconstr_lens[1]] = 0;
......@@ -164,6 +162,9 @@ check_xer(int fuzzy, double orig_value) {
assert(newst1->size == st.size);
assert(fuzzy || memcmp(newst0->buf, st.buf, st.size) == 0);
assert(memcmp(newst1->buf, st.buf, st.size) == 0);
ASN_STRUCT_RESET(asn_DEF_REAL, &st);
ASN_STRUCT_FREE(asn_DEF_REAL, newst0);
ASN_STRUCT_FREE(asn_DEF_REAL, newst1);
}
static void
......@@ -200,49 +201,56 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp
assert((size_t)rn.size == outsize);
}
assert(memcmp(rn.buf, outbuf, rn.size) == 0);
ASN_STRUCT_RESET(asn_DEF_REAL, &rn);
check_str_representation(d, sample, canonical_sample, lineno);
}
static void
check_ber_buffer_oneway(double d, const char *sample, const char *canonical_sample, uint8_t *buf, size_t bufsize, int lineno) {
REAL_t rn;
double val;
REAL_t rn0;
REAL_t rn1;
double val0;
double val1;
uint8_t *p, *end;
int ret;
memset(&rn, 0, sizeof(rn));
memset(&rn0, 0, sizeof(rn0));
memset(&rn1, 0, sizeof(rn1));
printf("verify double value %.12f [", d);
for(p = (uint8_t *)&d, end = p + sizeof(double); p < end ; p++)
printf("%02x", *p);
printf("] (ilogb %d)\n", ilogb(d));
ret = asn_double2REAL(&rn, d);
ret = asn_double2REAL(&rn0, d);
assert(ret == 0);
printf("canonical DER: [");
for(p = rn.buf, end = p + rn.size; p < end; p++)
for(p = rn0.buf, end = p + rn0.size; p < end; p++)
printf("%02x", *p);
printf("]\n");
ret = asn_REAL2double(&rn0, &val0);
assert(ret == 0);
printf("] => %f\n", val0);
rn.buf = buf;
rn.size = bufsize;
rn1.buf = buf;
rn1.size = bufsize;
printf("received as: [");
for(p = rn.buf, end = p + rn.size; p < end; p++)
for(p = rn1.buf, end = p + rn1.size; p < end; p++)
printf("%02x", *p);
printf("]\n");
ret = asn_REAL2double(&rn, &val);
ret = asn_REAL2double(&rn1, &val1);
assert(ret == 0);
printf("] => %f\n", val1);
printf("%.12f vs %.12f\n", d, val);
printf("%.12f vs %.12f vs %.12f\n", d, val0, val1);
assert(val == d);
assert(val0 == d);
assert(val1 == d);
check_str_representation(val, sample, canonical_sample, lineno);
ASN_STRUCT_RESET(asn_DEF_REAL, &rn0);
check_str_representation(val1, sample, canonical_sample, lineno);
}
/*
......@@ -696,5 +704,6 @@ main() {
check_xer(1, 0.0000000000000000000001);
check_xer(1, -0.0000000000000000000001);
ASN_STRUCT_RESET(asn_DEF_REAL, &rn);
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