From c3cf1a827807d11b07bce9d6941342c68808aab1 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 26 May 2011 13:57:03 -0700 Subject: [PATCH] Config utils improvement Added a function to free resources allocated by config node tree. Change-Id: I2ee8ae642899ec4501fa6e490c5be7efaa2d738e --- include/cutils/config_utils.h | 3 +++ libcutils/config_utils.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/cutils/config_utils.h b/include/cutils/config_utils.h index f3fb370a8..2dea6f19f 100644 --- a/include/cutils/config_utils.h +++ b/include/cutils/config_utils.h @@ -54,6 +54,9 @@ const char* config_str(cnode *root, const char *name, const char *_default); /* add a named child to a config node (or modify it if it already exists) */ void config_set(cnode *root, const char *name, const char *value); +/* free a config node tree */ +void config_free(cnode *root); + #ifdef __cplusplus } #endif diff --git a/libcutils/config_utils.c b/libcutils/config_utils.c index 75fa6c6d4..fc5ca7876 100644 --- a/libcutils/config_utils.c +++ b/libcutils/config_utils.c @@ -315,3 +315,15 @@ void config_load_file(cnode *root, const char *fn) data = load_file(fn, 0); config_load(root, data); } + +void config_free(cnode *root) +{ + cnode *cur = root->first_child; + + while (cur) { + cnode *prev = cur; + config_free(cur); + cur = cur->next; + free(prev); + } +}