From: Lucas De Marchi Date: Mon, 27 Feb 2012 22:54:33 +0000 (-0300) Subject: libkmod-index: free node when we have only partial match X-Git-Tag: v6~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=817f4e33de8b8cdbbd28f47caf094116a40da82e;p=thirdparty%2Fkmod.git libkmod-index: free node when we have only partial match --- diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index be4a2c23..1698d7fc 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -458,13 +458,12 @@ static char *index_search__node(struct index_node_f *node, const char *key, int i += j; if (key[i] == '\0') { - if (node->values) { - value = strdup(node->values[0].value); - index_close(node); - return value; - } else { - return NULL; - } + value = node->values != NULL + ? strdup(node->values[0].value) + : NULL; + + index_close(node); + return value; } child = index_readchild(node, key[i]); @@ -932,13 +931,12 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key, i += j; if (key[i] == '\0') { - if (node->values.len > 0) { - value = strdup(node->values.values[0].value); - index_mm_free_node(node); - return value; - } else { - return NULL; - } + value = node->values.len > 0 + ? strdup(node->values.values[0].value) + : NULL; + + index_mm_free_node(node); + return value; } child = index_mm_readchild(node, key[i]);