oconfig: fix oconfig_free to free all elements
authorMarc Fournier <marc.fournier@camptocamp.com>
Tue, 12 May 2015 20:40:27 +0000 (22:40 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Tue, 19 May 2015 15:41:27 +0000 (17:41 +0200)
The recursive nature of this function made it difficult to free the root
node of the config tree. Splitting it in 2 allows to work around this
problem.

src/java.c
src/liboconfig/oconfig.c

index 83cd353..10d837e 100644 (file)
@@ -3051,10 +3051,8 @@ static int cjni_init (void) /* {{{ */
 
   if (config_block != NULL)
   {
-
     cjni_config_perform (config_block);
     oconfig_free (config_block);
-    config_block = NULL;
   }
 
   if (jvm == NULL)
index 629775a..181eadd 100644 (file)
@@ -187,7 +187,7 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig)
   return (ci_copy);
 } /* oconfig_item_t *oconfig_clone */
 
-void oconfig_free (oconfig_item_t *ci)
+void oconfig_free_all (oconfig_item_t *ci)
 {
   int i;
 
@@ -206,12 +206,19 @@ void oconfig_free (oconfig_item_t *ci)
     free (ci->values);
 
   for (i = 0; i < ci->children_num; i++)
-    oconfig_free (ci->children + i);
+    oconfig_free_all (ci->children + i);
 
   if (ci->children != NULL)
     free (ci->children);
 }
 
+void oconfig_free (oconfig_item_t *ci)
+{
+  oconfig_free_all (ci);
+  free (ci);
+  ci = NULL;
+}
+
 /*
  * vim:shiftwidth=2:tabstop=8:softtabstop=2:fdm=marker
  */