From 04bbec2b89f820f64152f8a609c301d330b4d2c5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 4 Jan 2015 16:41:59 +0100 Subject: [PATCH] turns out that set_param with null should remove the setting. --- src/kernel/config.c | 11 +++++++++-- src/kernel/config.test.c | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 0e3d9802e..8cf3e0805 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1122,8 +1122,15 @@ void set_param(struct param **p, const char *key, const char *data) while (*p != NULL) { int cmp = strcmp((*p)->name, key); if (cmp == 0) { - free((*p)->data); - (*p)->data = _strdup(data); + par = *p; + free(par->data); + if (data) { + par->data = _strdup(data); + } + else { + *p = par->next; + free(par); + } return; } else if (cmp > 0) { diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index b5d7957be..34755c13b 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -71,6 +71,8 @@ static void test_get_set_param(CuTest * tc) set_param(&par, "bar", "foo"); CuAssertStrEquals(tc, "bar", get_param(par, "foo")); CuAssertStrEquals(tc, "foo", get_param(par, "bar")); + set_param(&par, "bar", NULL); + CuAssertPtrEquals(tc, NULL, (void *)get_param(par, "bar")); } static void test_param_int(CuTest * tc)