[sr-dev] git:master: tm: minor mem leak corrected

Miklos Tirpak miklos at iptel.org
Thu Sep 10 18:14:40 CEST 2009


Module: sip-router
Branch: master
Commit: 05af490239a5556704999d613e140e25425b0888
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=05af490239a5556704999d613e140e25425b0888

Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date:   Thu Sep 10 17:50:57 2009 +0200

tm: minor mem leak corrected

After the memory of a cell is allocated other modules
immediately have a chance to register transaction callbacks,
and they may also allocate additional memory for
the callback parameters. When sip_msg_cloner()
failed, the memory allocated for the callback
list was not freed. This happend only when the available
shm memory was already very low which caused sip_msg_cloner()
to fail.

---

 modules/tm/h_table.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/modules/tm/h_table.c b/modules/tm/h_table.c
index 11fb1a8..f72737e 100644
--- a/modules/tm/h_table.c
+++ b/modules/tm/h_table.c
@@ -266,6 +266,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
 	struct cell* new_cell;
 	int          sip_msg_len;
 	avp_list_t* old;
+	struct tm_callback *cbs, *cbs_tmp;
 
 	/* allocs a new cell */
 	/* if syn_branch==0 add space for md5 (MD5_LEN -sizeof(struct cell.md5)) */
@@ -343,6 +344,21 @@ struct cell*  build_cell( struct sip_msg* p_msg )
 	return new_cell;
 
 error:
+	/* Other modules may have already registered some
+	 * transaction callbacks and may also allocated
+	 * additional memory for their parameters,
+	 * hence TMCB_DESTROY needs to be called. (Miklos)
+	 */
+	if (unlikely(has_tran_tmcbs(new_cell, TMCB_DESTROY)))
+		run_trans_callbacks(TMCB_DESTROY, new_cell, 0, 0, 0);
+
+	/* free the callback list */
+	for( cbs=(struct tm_callback*)new_cell->tmcb_hl.first ; cbs ; ) {
+		cbs_tmp = cbs;
+		cbs = cbs->next;
+		shm_free_unsafe( cbs_tmp );
+	}
+	
 	destroy_avp_list(&new_cell->user_avps_from);
 	destroy_avp_list(&new_cell->user_avps_to);
 	destroy_avp_list(&new_cell->uri_avps_from);




More information about the sr-dev mailing list