X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_kvargs%2Frte_kvargs.c;h=8d56abd4c8bee40be83c756730693c29ce09b156;hb=7a7122edf1c8d63e516d1b2c2eff6fa9b54e0f82;hp=c7f626f2bb7c3eafefcc46d8eed9982317c3502b;hpb=d24839b318676504163dd3b4e9249ff1fe61b54d;p=dpdk.git diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index c7f626f2bb..8d56abd4c8 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -48,7 +48,9 @@ static int rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) { unsigned i; - char *str, *ctx1, *ctx2; + char *str; + char *ctx1 = NULL; + char *ctx2 = NULL; /* Copy the const char *params to a modifiable string * to pass to rte_strsplit @@ -139,7 +141,7 @@ rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match) ret = 0; for (i = 0; i < kvlist->count; i++) { pair = &kvlist->pairs[i]; - if (strcmp(pair->key, key_match) == 0) + if (key_match == NULL || strcmp(pair->key, key_match) == 0) ret++; } @@ -160,8 +162,8 @@ rte_kvargs_process(const struct rte_kvargs *kvlist, for (i = 0; i < kvlist->count; i++) { pair = &kvlist->pairs[i]; - if (strcmp(pair->key, key_match) == 0) { - if ((*handler)(pair->value, opaque_arg) < 0) + if (key_match == NULL || strcmp(pair->key, key_match) == 0) { + if ((*handler)(pair->key, pair->value, opaque_arg) < 0) return -1; } } @@ -172,8 +174,10 @@ rte_kvargs_process(const struct rte_kvargs *kvlist, void rte_kvargs_free(struct rte_kvargs *kvlist) { - if (kvlist->str != NULL) - free(kvlist->str); + if (!kvlist) + return; + + free(kvlist->str); free(kvlist); }