[asterisk-commits] tilghman: trunk r92507 - /trunk/main/asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 12 11:15:56 CST 2007


Author: tilghman
Date: Wed Dec 12 11:15:56 2007
New Revision: 92507

URL: http://svn.digium.com/view/asterisk?view=rev&rev=92507
Log:
Correctly handle possible memory allocation failure
Reported by: eliel
Patch by: eliel
(Closes issue #11512)

Modified:
    trunk/main/asterisk.c

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=92507&r1=92506&r2=92507
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Dec 12 11:15:56 2007
@@ -1983,7 +1983,7 @@
 
 static char **ast_el_strtoarr(char *buf)
 {
-	char **match_list = NULL, *retstr;
+	char **match_list = NULL, **match_list_tmp, *retstr;
 	size_t match_list_len;
 	int matches = 0;
 
@@ -1994,8 +1994,12 @@
 			break;
 		if (matches + 1 >= match_list_len) {
 			match_list_len <<= 1;
-			if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
-				/* TODO: Handle memory allocation failure */
+			if ((match_list_tmp = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
+				match_list = match_list_tmp;
+			} else {
+				if (match_list)
+					ast_free(match_list);
+				return (char **) NULL;
 			}
 		}
 
@@ -2006,8 +2010,12 @@
 		return (char **) NULL;
 
 	if (matches >= match_list_len) {
-		if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
-			/* TODO: Handle memory allocation failure */
+		if ((match_list_tmp = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
+			match_list = match_list_tmp;
+		} else {
+			if (match_list)
+				ast_free(match_list);
+			return (char **) NULL;
 		}
 	}
 




More information about the asterisk-commits mailing list