From d40c1d2c79141073bb19990cddca8a79dfc06532 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 11 Sep 2007 22:29:29 +0000 Subject: [PATCH] Fix for memory leak in xml-rpc (MDXMLINT-10) from Bret McDanel. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5699 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index e2d20b371a..a6aa1c0291 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -272,7 +272,7 @@ abyss_bool HandleHook(TSession * r) static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData) { - char *command, *arg; + char *command = NULL, *arg = NULL; switch_stream_handle_t stream = { 0 }; xmlrpc_value *val = NULL; @@ -280,7 +280,7 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * cons /* Parse our argument array. */ xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg); if (envP->fault_occurred) { - return NULL; + goto done; } SWITCH_STANDARD_STREAM(stream); @@ -292,20 +292,24 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * cons val = xmlrpc_build_value(envP, "s", "ERROR!"); } +done: + /* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */ + switch_safe_free(command); + switch_safe_free(arg); return val; } static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData) { - char *oid, *relative_oid, *s_action, *data; + char *oid = NULL, *relative_oid, *s_action = NULL, *data = NULL; char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = ""; switch_management_action_t action = SMA_NONE; - xmlrpc_value *val; + xmlrpc_value *val = NULL; /* Parse our argument array. */ xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data); if (envP->fault_occurred) { - return NULL; + goto done; } if (!strncasecmp(oid, FREESWITCH_OID_PREFIX, strlen(FREESWITCH_OID_PREFIX))) { @@ -343,7 +347,11 @@ static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * cons /* Return our result. */ val = xmlrpc_build_value(envP, "s", buf); - +done: + /* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */ + switch_safe_free(oid); + switch_safe_free(s_action); + switch_safe_free(data); return val; }