From: Marc Fournier Date: Tue, 12 May 2015 20:40:27 +0000 (+0200) Subject: oconfig: fix oconfig_free to free all elements X-Git-Tag: collectd-5.5.0~27^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ec9b92a7dc86c01156e3a132cbc591fc7d746226;p=collectd.git oconfig: fix oconfig_free to free all elements 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. --- diff --git a/src/java.c b/src/java.c index d0423be9..2f1efbf1 100644 --- a/src/java.c +++ b/src/java.c @@ -3078,10 +3078,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) diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index 539c9d35..bf21b90e 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -195,7 +195,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; @@ -214,12 +214,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 */