[asterisk-commits] branch 1.2 r9073 - /branches/1.2/res/res_odbc.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Feb 2 09:12:14 MST 2006


Author: mattf
Date: Thu Feb  2 10:12:13 2006
New Revision: 9073

URL: http://svn.digium.com/view/asterisk?rev=9073&view=rev
Log:
Fix for (#6309), potential (highly unlikely) memory leak in res_odbc

Modified:
    branches/1.2/res/res_odbc.c

Modified: branches/1.2/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/res/res_odbc.c?rev=9073&r1=9072&r2=9073&view=diff
==============================================================================
--- branches/1.2/res/res_odbc.c (original)
+++ branches/1.2/res/res_odbc.c Thu Feb  2 10:12:13 2006
@@ -428,39 +428,41 @@
 {
 	static odbc_obj *new;
 
-	new = malloc(sizeof(odbc_obj));
-	if (!new)
-		return NULL;
-	memset(new, 0, sizeof(odbc_obj));
-	new->env = SQL_NULL_HANDLE;
-
-	new->name = malloc(strlen(name) + 1);
-	if (new->name == NULL)
-		return NULL;
-
-	new->dsn = malloc(strlen(dsn) + 1);
-	if (new->dsn == NULL)
-		return NULL;
+	if (!(new = calloc(1, sizeof(*new))) || 
+	    !(new->name = malloc(strlen(name) + 1)) || 
+	    !(new->dsn = malloc(strlen(dsn) + 1)))
+	    	goto cleanup;
 
 	if (username) {
-		new->username = malloc(strlen(username) + 1);
-		if (new->username == NULL)
-			return NULL;
+		if (!(new->username = malloc(strlen(username) + 1)))
+			goto cleanup;
 		strcpy(new->username, username);
 	}
 
 	if (password) {
-		new->password = malloc(strlen(password) + 1);
-		if (new->password == NULL)
-			return NULL;
+		if (!(new->password = malloc(strlen(password) + 1)))
+			goto cleanup;
 		strcpy(new->password, password);
 	}
 
 	strcpy(new->name, name);
 	strcpy(new->dsn, dsn);
+	new->env = SQL_NULL_HANDLE;
 	new->up = 0;
 	ast_mutex_init(&new->lock);
 	return new;
+
+cleanup:
+	if (new) {
+		free(new->name);
+		free(new->dsn);
+		free(new->username);
+		free(new->password);
+
+		free(new);	
+	}
+
+	return NULL;
 }
 
 void destroy_odbc_obj(odbc_obj **obj)



More information about the asterisk-commits mailing list