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)