[asterisk-commits] tilghman: trunk r197616 - in /trunk: apps/ channels/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 28 10:35:29 CDT 2009


Author: tilghman
Date: Thu May 28 10:35:23 2009
New Revision: 197616

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=197616
Log:
Eliminate several needless checks and fix a few memory leaks
(closes issue #14833)
 Reported by: contactmayankjain
 Patches: 
       all_changes.patch uploaded by contactmayankjain (license 740)
       slightly modified by me

Modified:
    trunk/apps/app_rpt.c
    trunk/channels/chan_console.c
    trunk/channels/chan_dahdi.c
    trunk/main/astobj2.c
    trunk/main/cli.c

Modified: trunk/apps/app_rpt.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/apps/app_rpt.c?view=diff&rev=197616&r1=197615&r2=197616
==============================================================================
--- trunk/apps/app_rpt.c (original)
+++ trunk/apps/app_rpt.c Thu May 28 10:35:23 2009
@@ -1957,7 +1957,11 @@
 	if (!myrpt->p.statpost_url) return;
 	str = ast_malloc(strlen(pairs) + strlen(myrpt->p.statpost_url) + 200);
 	astr = ast_strdup(myrpt->p.statpost_program);
-	if ((!str) || (!astr)) return;
+	if ((!str) || (!astr)) {
+		ast_free(str);
+		ast_free(astr);
+		return;
+	}
 	n = finddelim(astr,astrs,100);
 	if (n < 1) return;
 	ast_mutex_lock(&myrpt->statpost_lock);
@@ -2895,12 +2899,8 @@
 			for(j = 0; j < numoflinks; j++){ /* ast_free() all link names */
 				ast_free(listoflinks[j]);
 			}
-			if(called_number){
-				ast_free(called_number);
-			}
-			if(lastdtmfcommand){
-				ast_free(lastdtmfcommand);
-			}
+			ast_free(called_number);
+			ast_free(lastdtmfcommand);
 		        return RESULT_SUCCESS;
 		}
 	}
@@ -3646,8 +3646,7 @@
 		if(res)
 			break;
 	}
-	if(p)
-		ast_free(p);
+	ast_free(p);
 	if(!res)
 		res = play_tone_pair(chan, 0, 0, 100, 0); /* This is needed to ensure the last tone segment is timed correctly */
 	
@@ -3828,8 +3827,7 @@
 	else{
 		res = -1;
 	}
-	if(telemetry_save)
-		ast_free(telemetry_save);
+	ast_free(telemetry_save);
 	return res;
 }
 
@@ -3907,8 +3905,7 @@
 			interval = 0;
 			break;
         }
-	if(wait_times_save)
-       		ast_free(wait_times_save);
+	ast_free(wait_times_save);
 	return interval;
 }                                                                                                                  
 

Modified: trunk/channels/chan_console.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/channels/chan_console.c?view=diff&rev=197616&r1=197615&r2=197616
==============================================================================
--- trunk/channels/chan_console.c (original)
+++ trunk/channels/chan_console.c Thu May 28 10:35:23 2009
@@ -838,8 +838,7 @@
 	} else
 		ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
 
-	if (s)
-		free(s);
+	free(s);
 
 	unref_pvt(pvt);
 

Modified: trunk/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/channels/chan_dahdi.c?view=diff&rev=197616&r1=197615&r2=197616
==============================================================================
--- trunk/channels/chan_dahdi.c (original)
+++ trunk/channels/chan_dahdi.c Thu May 28 10:35:23 2009
@@ -10183,8 +10183,6 @@
 
 	if (!here && reloading != 1) {
 		if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
-			if (tmp)
-				free(tmp);
 			return NULL;
 		}
 		ast_mutex_init(&tmp->lock);

Modified: trunk/main/astobj2.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/astobj2.c?view=diff&rev=197616&r1=197615&r2=197616
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Thu May 28 10:35:23 2009
@@ -342,11 +342,11 @@
 	void *obj;
 	FILE *refo = ref_debug ? fopen(REF_FILE,"a") : NULL;
 
-	obj = internal_ao2_alloc(data_size, destructor_fn, file, line, funcname);
-
-	if (obj == NULL)
-		return NULL;
-	
+	if ((obj = internal_ao2_alloc(data_size, destructor_fn, file, line, funcname)) == NULL) {
+		fclose(refo);
+		return NULL;
+	}
+
 	if (refo) {
 		fprintf(refo, "%p =1   %s:%d:%s (%s)\n", obj, file, line, funcname, tag);
 		fclose(refo);

Modified: trunk/main/cli.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/cli.c?view=diff&rev=197616&r1=197615&r2=197616
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Thu May 28 10:35:23 2009
@@ -235,8 +235,7 @@
 		c += (strlen(ast_config_AST_MODULE_DIR) + 1);
 	if (c)
 		c = ast_strdup(c);
-	if (d)
-		free(d);
+	free(d);
 	
 	return c;
 }




More information about the asterisk-commits mailing list