Skip to content

Commit

Permalink
Config utils improvement
Browse files Browse the repository at this point in the history
Added a function to free resources allocated by config node tree.

Change-Id: I2ee8ae642899ec4501fa6e490c5be7efaa2d738e
  • Loading branch information
Eric Laurent committed May 26, 2011
1 parent 7956d75 commit c3cf1a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/cutils/config_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions libcutils/config_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c3cf1a8

Please sign in to comment.