- Fix memory leak error when freeing node.

- Cleanup ConfDump output a little.
remotes/origin/master-1.0.x
Jason Ish 17 years ago committed by Victor Julien
parent 4c79e6d5b6
commit 6cc0771d6f

@ -145,8 +145,10 @@ ConfNodeFree(ConfNode *node)
{ {
ConfNode *tmp; ConfNode *tmp;
TAILQ_FOREACH(tmp, &node->head, next) while (tmp = TAILQ_FIRST(&node->head)) {
TAILQ_REMOVE(&node->head, tmp, next);
ConfNodeFree(tmp); ConfNodeFree(tmp);
}
if (node->name != NULL) if (node->name != NULL)
free(node->name); free(node->name);
@ -396,16 +398,43 @@ ConfDeInit(void)
SCLogDebug("configuration module de-initialized"); SCLogDebug("configuration module de-initialized");
} }
static char *
ConfPrintNameArray(const char **name_arr, int level)
{
static char name[128*128];
int i;
name[0] = '\0';
for (i = 0; i <= level; i++) {
strcat(name, name_arr[i]);
if (i < level)
strcat(name, ".");
}
return name;
}
/**
* \brief Dump a configuration node and all its children.
*/
void void
ConfNodeDump(ConfNode *node) ConfNodeDump(ConfNode *node, const char *prefix)
{ {
ConfNode *child; ConfNode *child;
static char *name[128];
static int level = -1;
level++;
TAILQ_FOREACH(child, &node->head, next) { TAILQ_FOREACH(child, &node->head, next) {
printf("%s = %s\n", child->name, child->val); name[level] = strdup(child->name);
if (child->val == NULL) if (child->val != NULL)
ConfNodeDump(child); printf("%s.%s = %s\n", prefix,
ConfPrintNameArray(name, level), child->val);
ConfNodeDump(child, prefix);
free(name[level]);
} }
level--;
} }
/** /**
@ -423,13 +452,9 @@ ConfDump(void)
b = (HashTableBucket *)conf_hash->array[i]; b = (HashTableBucket *)conf_hash->array[i];
while (b != NULL) { while (b != NULL) {
cn = (ConfNode *)b->data; cn = (ConfNode *)b->data;
if (cn->val != NULL)
printf("%s = %s\n", cn->name, cn->val); printf("%s = %s\n", cn->name, cn->val);
if (!TAILQ_EMPTY(&cn->head)) { ConfNodeDump(cn, cn->name);
ConfNode *n0;
TAILQ_FOREACH(n0, &cn->head, next) {
printf(".%s\n", n0->val);
}
}
b = b->next; b = b->next;
} }
} }

@ -34,7 +34,7 @@ int ConfGetInt(char *name, intmax_t *val);
int ConfGetBool(char *name, int *val); int ConfGetBool(char *name, int *val);
int ConfSet(char *name, char *val, int allow_override); int ConfSet(char *name, char *val, int allow_override);
void ConfDump(void); void ConfDump(void);
void ConfNodeDump(ConfNode *node); void ConfNodeDump(ConfNode *node, const char *prefix);
ConfNode *ConfNodeNew(void); ConfNode *ConfNodeNew(void);
void ConfNodeFree(ConfNode *); void ConfNodeFree(ConfNode *);
int ConfSetNode(ConfNode *node); int ConfSetNode(ConfNode *node);

Loading…
Cancel
Save