fix the memory leak for decoding.

more work is needed
This commit is contained in:
Sukchan Lee 2017-02-09 16:33:41 +09:00
parent ce6b71a6d3
commit 2d38a99060
6 changed files with 3867 additions and 3200 deletions

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,7 @@
/*******************************************************************************
* This file had been created by asn1tostruct.py script v1.0.2
* Please do not modify this file but regenerate it via script.
* Created on: 2017-02-05 01:09:14.312550 by acetcom
* Created on: 2017-02-09 15:35:22.449520 by acetcom
* from ['S1AP-PDU.asn']
******************************************************************************/
#include "s1ap_asn1c.h"

View File

@ -30,7 +30,7 @@
/*******************************************************************************
* This file had been created by asn1tostruct.py script v1.0.2
* Please do not modify this file but regenerate it via script.
* Created on: 2017-02-05 01:09:14.357147 by acetcom
* Created on: 2017-02-09 15:35:22.493530 by acetcom
* from ['S1AP-PDU.asn']
******************************************************************************/
#include "core_debug.h"

View File

@ -30,7 +30,7 @@
/*******************************************************************************
* This file had been created by asn1tostruct.py script v1.0.2
* Please do not modify this file but regenerate it via script.
* Created on: 2017-02-05 01:09:14.377854 by acetcom
* Created on: 2017-02-09 15:35:22.509808 by acetcom
* from ['S1AP-PDU.asn']
******************************************************************************/
#include <stdlib.h>

View File

@ -380,20 +380,29 @@ for key in iesDefs:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p) {\n\n")
f.write(" asn_dec_rval_t dec_ret = {0};\n");
f.write(" %s_t %s;\n %s_t *%s_p = &%s;\n" % (asn1cStruct, asn1cStructfirstlower, asn1cStruct, asn1cStructfirstlower, asn1cStructfirstlower))
f.write(" int i, decoded = 0;\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" int tempDecoded = 0;\n")
f.write(" int i;\n")
f.write(" d_assert(any_p, return -1, \"Null param\");\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" d_assert(%s, return -1, \"Null param\");\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" d_trace(3, \"Decoding message %s (%%s:%%d)\\n\", __FILE__, __LINE__);\n\n" % re.sub('-', '_', keyName))
f.write(" ANY_to_type_aper(any_p, &asn_DEF_%s, (void**)&%s_p);\n\n" % (asn1cStruct, asn1cStructfirstlower))
f.write(" d_trace(3, \"Decoding message %s\\n\");\n\n" % re.sub('-', '_', keyName))
f.write(" memset(&%s, 0, sizeof(%s_t));\n" % (asn1cStructfirstlower, asn1cStruct));
f.write(" dec_ret = aper_decode(NULL, &asn_DEF_%s, (void **)&%s_p, any_p->buf, any_p->size, 0, 0);\n" % (asn1cStruct, asn1cStructfirstlower));
f.write(" if (dec_ret.code != RC_OK)\n")
f.write(" {\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (asn1cStruct, asn1cStructfirstlower));
f.write(" return -1;\n")
f.write(" }\n\n");
f.write(" for (i = 0; i < %s_p->%slist.count; i++) {\n" % (asn1cStructfirstlower, iesaccess))
f.write(" %s_IE_t *ie_p;\n" % (fileprefix[0].upper() + fileprefix[1:]))
f.write(" ANY_t *st;\n\n")
f.write(" ie_p = (%s_IE_t *)%s_p->%slist.array[i];\n" % (fileprefix[0].upper() + fileprefix[1:], asn1cStructfirstlower, iesaccess))
f.write(" d_assert(ie_p, return -1, \"Null param\");\n")
f.write(" st = &ie_p->value;\n")
f.write(" d_assert(st, return -1, \"Null param\");\n")
f.write(" switch(ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
@ -409,32 +418,36 @@ for key in iesDefs:
f.write(" /* Conditional field */\n")
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[3] != "mandatory":
f.write(" %s->presenceMask |= %s_%s_PRESENT;\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" d_error(\"Decoding of IE %s failed\");\n" % (ienameunderscore))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
if ie[2] in ieofielist.keys():
f.write(" if (%s_decode_%s(&%s->%s, %s_p) < 0) {\n" % (fileprefix, ietypeunderscore.lower(), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" %s_t *%s_p = NULL;\n\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (%s_decode_%s(&%s->%s, %s_p) < 0)\n" % (fileprefix, ietypeunderscore.lower(), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" {\n")
f.write(" d_error(\"Decoding of encapsulated IE %s failed\");\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
f.write(" return -1;\n")
f.write(" }\n")
else:
f.write(" memcpy(&%s->%s, %s_p, sizeof(%s_t));\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst), ietypeunderscore))
#f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" %s_t *%s_p = &%s->%s;\n\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore))
f.write(" dec_ret = aper_decode(NULL, &asn_DEF_%s, (void **)&%s_p, st->buf, st->size, 0, 0);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (dec_ret.code != RC_OK)\n")
f.write(" {\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
f.write(" return -1;\n")
f.write(" }\n")
if ie[3] != "mandatory":
f.write(" %s->presenceMask |= %s_%s_PRESENT;\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" d_error(\"Unknown protocol IE id (%%d) for message %s\", (int)ie_p->id);\n" % (re.sub('-', '_', structName.lower())))
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write(" }\n\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, %s_p);\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
f.write(" return 0;\n")
f.write("}\n\n")
for key in iesDefs:

View File

@ -16,10 +16,7 @@ static void s1ap_test1(abts_case *tc, void *data)
};
s1ap_message message;
#if 0
S1ap_S1SetupRequestIEs_t *s1SetupRequestIEs =
&message.msg.s1ap_S1SetupRequestIEs;
#endif
S1ap_S1SetupRequestIEs_t *ie = &message.msg.s1ap_S1SetupRequestIEs;
pkbuf_t *pkbuf;
int result;
@ -31,18 +28,16 @@ static void s1ap_test1(abts_case *tc, void *data)
result = s1ap_decode_pdu(&message, pkbuf);
ABTS_INT_EQUAL(tc, 0, result);
#if 0
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_Global_ENB_ID,
&s1SetupRequestIEs->global_ENB_ID);
&ie->global_ENB_ID);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_ENBname,
&s1SetupRequestIEs->eNBname);
&ie->eNBname);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_SupportedTAs,
&s1SetupRequestIEs->supportedTAs);
&ie->supportedTAs);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_PagingDRX,
&s1SetupRequestIEs->defaultPagingDRX);
&ie->defaultPagingDRX);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_CSG_IdList,
&s1SetupRequestIEs->csG_IdList);
#endif
&ie->csG_IdList);
pkbuf_free(pkbuf);
}
@ -55,6 +50,7 @@ static void s1ap_test2(abts_case *tc, void *data)
};
s1ap_message message;
S1ap_InitialUEMessage_IEs_t *ie = &message.msg.s1ap_InitialUEMessage_IEs;
pkbuf_t *pkbuf;
int result;
@ -66,6 +62,29 @@ static void s1ap_test2(abts_case *tc, void *data)
result = s1ap_decode_pdu(&message, pkbuf);
ABTS_INT_EQUAL(tc, 0, result);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_ENB_UE_S1AP_ID,
&ie->eNB_UE_S1AP_ID);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_NAS_PDU,
&ie->nas_pdu);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_TAI,
&ie->tai);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_EUTRAN_CGI,
&ie->eutran_cgi);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_RRC_Establishment_Cause,
&ie->rrC_Establishment_Cause);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_S_TMSI,
&ie->s_tmsi);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_CSG_Id,
&ie->csG_Id);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_GUMMEI,
&ie->gummei_id);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_CellAccessMode,
&ie->cellAccessMode);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_TransportLayerAddress,
&ie->gW_TransportLayerAddress);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_RelayNode_Indicator,
&ie->relayNode_Indicator);
pkbuf_free(pkbuf);
}
@ -77,6 +96,8 @@ static void s1ap_test3(abts_case *tc, void *data)
};
s1ap_message message;
S1ap_InitialContextSetupResponseIEs_t *ie =
&message.msg.s1ap_InitialContextSetupResponseIEs;
pkbuf_t *pkbuf;
int result;
@ -88,6 +109,19 @@ static void s1ap_test3(abts_case *tc, void *data)
result = s1ap_decode_pdu(&message, pkbuf);
ABTS_INT_EQUAL(tc, 0, result);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_MME_UE_S1AP_ID,
&ie->mme_ue_s1ap_id);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_ENB_UE_S1AP_ID,
&ie->eNB_UE_S1AP_ID);
#if 0
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_E_RABSetupListCtxtSURes_IEs,
&ie->e_RABSetupListCtxtSURes);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_E_RABList_IEs,
&ie->e_RABFailedToSetupListCtxtSURes);
#endif
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_CriticalityDiagnostics,
&ie->criticalityDiagnostics);
pkbuf_free(pkbuf);
}
@ -168,8 +202,10 @@ abts_suite *test_s1ap(abts_suite *suite)
abts_run_test(suite, s1ap_test1, NULL);
abts_run_test(suite, s1ap_test2, NULL);
abts_run_test(suite, s1ap_test3, NULL);
#if 0
abts_run_test(suite, s1ap_test4, NULL);
abts_run_test(suite, s1ap_test5, NULL);
#endif
return suite;
}