Revision
15242
Author
mochouinard
Date
2009-10-27 00:51:23 -0500 (Tue, 27 Oct 2009)

Log Message

mod_sofia: Fix memleaks

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (15241 => 15242)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2009-10-26 23:30:17 UTC (rev 15241)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2009-10-27 05:51:23 UTC (rev 15242)
@@ -706,7 +706,7 @@
 	sip_expires_t const *expires = NULL;
 	sip_authorization_t const *authorization = NULL;
 	sip_contact_t const *contact = NULL;
-	char *sql;
+	char *sql = NULL;
 	switch_event_t *s_event;
 	const char *to_user = NULL;
 	const char *to_host = NULL;
@@ -1072,6 +1072,7 @@
 		}
 		switch_mutex_lock(profile->ireg_mutex);
 		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+		switch_safe_free(sql);
 
 		switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
 		sql = switch_mprintf("insert into sip_registrations "
@@ -1085,6 +1086,7 @@
 		if (sql) {
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 		}
+		switch_safe_free(sql);
 
 		switch_mutex_unlock(profile->ireg_mutex);
 
@@ -1186,6 +1188,7 @@
 			}
 
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+			switch_safe_free(sql);
 
 			if (multi_reg_contact) {
 				sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
@@ -1194,16 +1197,19 @@
 			}
 
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+			switch_safe_free(sql);
 
 			switch_safe_free(icontact);
 		} else {
 			if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, reg_host))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
+			switch_safe_free(sql);
 
 			if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
+			switch_safe_free(sql);
 		}
 	}
 
@@ -1592,7 +1598,7 @@
 	const char *passwd = NULL;
 	const char *a1_hash = NULL;
 	const char *mwi_account = NULL;
-	char *sql;
+	char *sql = NULL;
 	char *number_alias = NULL;
 	switch_xml_t domain, xml = NULL, user, param, uparams, dparams, group = NULL, gparams = NULL;
 	char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
@@ -1661,11 +1667,11 @@
 		sql = switch_mprintf("select nonce from sip_authentication where nonce='%q'", nonce);
 		switch_assert(sql != NULL);
 		if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) {
-			free(sql);
+			switch_safe_free(sql);
 			ret = AUTH_STALE;
 			goto end;
 		}
-		free(sql);
+		switch_safe_free(sql);
 	}
 
 	switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);