[asterisk-commits] eliel: branch group/data_api_gsoc2009 r209451 - /team/group/data_api_gsoc2009...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 29 09:23:50 CDT 2009


Author: eliel
Date: Wed Jul 29 09:23:46 2009
New Revision: 209451

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=209451
Log:
Fix a memory leak in the provider tree.


Modified:
    team/group/data_api_gsoc2009/main/data.c

Modified: team/group/data_api_gsoc2009/main/data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/data.c?view=diff&rev=209451&r1=209450&r2=209451
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Wed Jul 29 09:23:46 2009
@@ -252,6 +252,17 @@
 
 /*!
  * \internal
+ * \brief Release the memory allocated by a call to ao2_alloc.
+ */
+static void data_provider_destructor(void *obj)
+{
+	struct data_provider *provider = obj;
+
+	ao2_ref(provider->children, -1);
+}
+
+/*!
+ * \internal
  * \brief Create a new data node.
  * \param[in] name The name of the node we are going to create.
  * \param[in] handler The handler registered for this node.
@@ -267,7 +278,7 @@
 
 	namelen = strlen(name) + 1;
 
-	node = ao2_alloc(sizeof(*node) + namelen, NULL);
+	node = ao2_alloc(sizeof(*node) + namelen, data_provider_destructor);
 	if (!node) {
 		return NULL;
 	}
@@ -1344,6 +1355,11 @@
 	/* release the temporary created node used for searching. */
 	ao2_ref(find_node, -1);
 
+	/* do not increment the reference counter, we are not using it. */
+	if (found) {
+		ao2_ref(found, -1);
+	}
+
 	return found;
 }
 




More information about the asterisk-commits mailing list