[asterisk-commits] rmudgett: trunk r332615 - /trunk/res/res_config_ldap.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 19 12:24:59 CDT 2011


Author: rmudgett
Date: Fri Aug 19 12:24:56 2011
New Revision: 332615

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=332615
Log:
Fix infinite loop releasing the same memory in ldap_loadentry().

* Fixed memory leak of vars in ldap_loadentry().

* Fixed potential NULL ptr dereference of vars in ldap_loadentry().

Modified:
    trunk/res/res_config_ldap.c

Modified: trunk/res/res_config_ldap.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_config_ldap.c?view=diff&rev=332615&r1=332614&r2=332615
==============================================================================
--- trunk/res/res_config_ldap.c (original)
+++ trunk/res/res_config_ldap.c Fri Aug 19 12:24:56 2011
@@ -609,16 +609,16 @@
 		/* Chopping \a vars down to one variable */
 		if (vars != NULL) {
 			struct ast_variable **p = vars;
-			p++;
-			var = *p;
-			while (var) {
-				ast_variables_destroy(var);
-				p++;
-			}
-			vars = ast_realloc(vars, sizeof(struct ast_variable *));
-		}
-
-		var = *vars;
+
+			/* Only take the first one. */
+			var = *vars;
+
+			/* Destroy the rest. */
+			while (*++p) {
+				ast_variables_destroy(*p);
+			}
+			ast_free(vars);
+		}
 
 		return var;
 	}
@@ -864,6 +864,11 @@
 								ast_variables_destroy(base_var);
 								base_var = next;
 							} else {
+								/*!
+								 * \todo XXX The interactions with base_var and append_var may
+								 * cause a memory leak of base_var nodes.  Also the append_var
+								 * list and base_var list may get cross linked.
+								 */
 								if (append_var) {
 									base_var->next = append_var;
 								} else {
@@ -926,6 +931,8 @@
 	if (vars) {
 		struct ast_variable *last_var = NULL;
 		struct ast_variable **p = vars;
+
+		/* Chain the vars array of lists into one list to return. */
 		while (*p) {
 			if (last_var) {
 				while (last_var->next) {




More information about the asterisk-commits mailing list