From e19bafe8943aeb1ee73e996f36209bca1c2eef40 Mon Sep 17 00:00:00 2001 From: William King Date: Wed, 7 May 2014 00:37:32 -0700 Subject: [PATCH] CID: 1211950 fix memory leak of iksparser in function nlsml_parse in mod_rayo --- src/mod/event_handlers/mod_rayo/nlsml.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/nlsml.c b/src/mod/event_handlers/mod_rayo/nlsml.c index b050565071..e166742be8 100644 --- a/src/mod/event_handlers/mod_rayo/nlsml.c +++ b/src/mod/event_handlers/mod_rayo/nlsml.c @@ -313,29 +313,37 @@ static int cdata_hook(void *user_data, char *data, size_t len) enum nlsml_match_type nlsml_parse(const char *result, const char *uuid) { struct nlsml_parser parser = { 0 }; + int result = NMT_BAD_XML; + iksparser *p = NULL; parser.uuid = uuid; + if (!zstr(result)) { - iksparser *p = iks_sax_new(&parser, tag_hook, cdata_hook); + p = iks_sax_new(&parser, tag_hook, cdata_hook); if (iks_parse(p, result, 0, 1) == IKS_OK) { /* check result */ if (parser.match) { - return NMT_MATCH; + result = NMT_MATCH; + goto end; } if (parser.nomatch) { - return NMT_NOMATCH; + result = NMT_NOMATCH; + goto end; } if (parser.noinput) { - return NMT_NOINPUT; + result = NMT_NOINPUT; + goto end; } switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser.uuid), SWITCH_LOG_INFO, "NLSML result does not have match/noinput/nomatch!\n"); } else { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser.uuid), SWITCH_LOG_INFO, "Failed to parse NLSML!\n"); } - iks_parser_delete(p); } else { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser.uuid), SWITCH_LOG_INFO, "Missing NLSML result\n"); } - return NMT_BAD_XML; + end: + if ( p ) + iks_parser_delete(p); + return result; } #define NLSML_NS "http://www.ietf.org/xml/ns/mrcpv2"