[sr-dev] git:bpintea/asi_binrpc2: b/f: in case of SHM OOM, new_dlg_uac() was leaking even more SHM

Bogdan Pintea bogdan at iptego.com
Thu Jan 14 23:21:35 CET 2010


Module: sip-router
Branch: bpintea/asi_binrpc2
Commit: 26c6d4dbdbe552ca8a041c1e6beb22d4bbd818c2
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=26c6d4dbdbe552ca8a041c1e6beb22d4bbd818c2

Author: bpi <bpi at machine.office.iptego.net>
Committer: bpi <bpi at machine.office.iptego.net>
Date:   Thu Jan 14 22:34:45 2010 +0100

b/f: in case of SHM OOM, new_dlg_uac() was leaking even more SHM

---

 modules/tm/dlg.c |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/modules/tm/dlg.c b/modules/tm/dlg.c
index c18f5c2..8012c1d 100644
--- a/modules/tm/dlg.c
+++ b/modules/tm/dlg.c
@@ -320,41 +320,40 @@ int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _rur
 		return -1;
 	}
 
-	res = (dlg_t*)shm_malloc(sizeof(dlg_t));
-	if (res == 0) {
-		LOG(L_ERR, "new_dlg_uac(): No memory left\n");
-		return -2;
+	if (! (res = (dlg_t*)shm_malloc(sizeof(dlg_t)))) {
+		ERR("out of shm mem.\n");
+		return -1;
+	} else {
+		memset(res, 0, sizeof(dlg_t));
 	}
-
-	     /* Clear everything */	
-	memset(res, 0, sizeof(dlg_t));
 	
 	     /* Make a copy of Call-ID */
-	if (str_duplicate(&res->id.call_id, _cid) < 0) return -3;
+	if (str_duplicate(&res->id.call_id, _cid) < 0) goto failed;
 	     /* Make a copy of local tag (usually From tag) */
-	if (str_duplicate(&res->id.loc_tag, _ltag) < 0) return -4;
+	if (str_duplicate(&res->id.loc_tag, _ltag) < 0) goto failed;
 	     /* Make a copy of local URI (usually From) */
-	if (str_duplicate(&res->loc_uri, _luri) < 0) return -5;
+	if (str_duplicate(&res->loc_uri, _luri) < 0) goto failed;
 	     /* Make a copy of remote URI (usually To) */
-	if (str_duplicate(&res->rem_uri, _ruri) < 0) return -6;
+	if (str_duplicate(&res->rem_uri, _ruri) < 0) goto failed;
 	     /* Make a copy of local sequence (usually CSeq) */
 	res->loc_seq.value = _lseq;
 	     /* And mark it as set */
 	res->loc_seq.is_set = 1;
 
-	*_d = res;
-
-	if (calculate_hooks(*_d) < 0) {
-		LOG(L_ERR, "new_dlg_uac(): Error while calculating hooks\n");
-		/* FIXME: free everything here */
-		shm_free(res);
-		return -2;
+	if (calculate_hooks(res) < 0) {
+		ERR("failed calculating hooks\n");
+		goto failed;
 	}
 #ifdef DIALOG_CALLBACKS
 	run_new_dlg_callbacks(DLG_CB_UAC, res, 0);
 #endif
 	
+	*_d = res;
 	return 0;
+
+failed:
+	free_dlg(res);
+	return -1;
 }
 
 




More information about the sr-dev mailing list