Browse code

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

bpi authored on 14/01/2010 21:34:45
Showing 1 changed files
... ...
@@ -320,41 +320,40 @@ int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _rur
320 320
 		return -1;
321 321
 	}
322 322
 
323
-	res = (dlg_t*)shm_malloc(sizeof(dlg_t));
324
-	if (res == 0) {
325
-		LOG(L_ERR, "new_dlg_uac(): No memory left\n");
326
-		return -2;
323
+	if (! (res = (dlg_t*)shm_malloc(sizeof(dlg_t)))) {
324
+		ERR("out of shm mem.\n");
325
+		return -1;
326
+	} else {
327
+		memset(res, 0, sizeof(dlg_t));
327 328
 	}
328
-
329
-	     /* Clear everything */	
330
-	memset(res, 0, sizeof(dlg_t));
331 329
 	
332 330
 	     /* Make a copy of Call-ID */
333
-	if (str_duplicate(&res->id.call_id, _cid) < 0) return -3;
331
+	if (str_duplicate(&res->id.call_id, _cid) < 0) goto failed;
334 332
 	     /* Make a copy of local tag (usually From tag) */
335
-	if (str_duplicate(&res->id.loc_tag, _ltag) < 0) return -4;
333
+	if (str_duplicate(&res->id.loc_tag, _ltag) < 0) goto failed;
336 334
 	     /* Make a copy of local URI (usually From) */
337
-	if (str_duplicate(&res->loc_uri, _luri) < 0) return -5;
335
+	if (str_duplicate(&res->loc_uri, _luri) < 0) goto failed;
338 336
 	     /* Make a copy of remote URI (usually To) */
339
-	if (str_duplicate(&res->rem_uri, _ruri) < 0) return -6;
337
+	if (str_duplicate(&res->rem_uri, _ruri) < 0) goto failed;
340 338
 	     /* Make a copy of local sequence (usually CSeq) */
341 339
 	res->loc_seq.value = _lseq;
342 340
 	     /* And mark it as set */
343 341
 	res->loc_seq.is_set = 1;
344 342
 
345
-	*_d = res;
346
-
347
-	if (calculate_hooks(*_d) < 0) {
348
-		LOG(L_ERR, "new_dlg_uac(): Error while calculating hooks\n");
349
-		/* FIXME: free everything here */
350
-		shm_free(res);
351
-		return -2;
343
+	if (calculate_hooks(res) < 0) {
344
+		ERR("failed calculating hooks\n");
345
+		goto failed;
352 346
 	}
353 347
 #ifdef DIALOG_CALLBACKS
354 348
 	run_new_dlg_callbacks(DLG_CB_UAC, res, 0);
355 349
 #endif
356 350
 	
351
+	*_d = res;
357 352
 	return 0;
353
+
354
+failed:
355
+	free_dlg(res);
356
+	return -1;
358 357
 }
359 358
 
360 359