From 844b1265d16014747e493cd757cd959b7ff9c872 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 9 Dec 2013 07:08:21 -0500 Subject: [PATCH] free the mallocs --- src/tcap.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/tcap.c b/src/tcap.c index fc5413a..1fd71f4 100644 --- a/src/tcap.c +++ b/src/tcap.c @@ -67,6 +67,8 @@ void *inap_decode(Invoke_t *invoke, asn_TYPE_descriptor_t **type) { goto nothing; *type = opcode_type_map[opcode]; + if (!*type) + goto nothing; rv = ANY_to_type(invoke->parameter, *type, &arg); @@ -201,7 +203,17 @@ error: int tcap_extract(const char *buf, size_t len, const char *spec, struct output_buffer *out) { - return asn1_extract(spec, out, &asn_DEF_TCMessage, tcap_decode(buf, len)); + TCMessage_t *tcm; + int ret; + + tcm = tcap_decode(buf, len); + if (!tcm) + return -1; + + ret = asn1_extract(spec, out, &asn_DEF_TCMessage, tcm); + + asn_DEF_TCMessage.free_struct(&asn_DEF_TCMessage, tcm, 0); + return ret; } @@ -269,13 +281,17 @@ int inap_extract(const char *buf, size_t len, const char *spec, struct output_bu found_parameter: if (next_token_2(&token, &c)) - goto out; + i = 0; + else + i = asn1_extract(token, out, type, parameter); - return asn1_extract(token, out, type, parameter); + asn_DEF_TCMessage.free_struct(&asn_DEF_TCMessage, tcm, 0); + type->free_struct(type, parameter, 0); -out: - return 0; + return i; error: + if (tcm) + asn_DEF_TCMessage.free_struct(&asn_DEF_TCMessage, tcm, 0); return -1; }