From c34af7424e092bd5e12ae84993a6ba64fe64d18f Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Wed, 25 Feb 2015 13:41:24 +0100 Subject: [PATCH] kvargs: fix freeing behaviour for null By convention free() functions should ignore NULL parameter. This patch add this behaviour for rte_kvargs_free(). Signed-off-by: Pawel Wodkowski Acked-by: Olivier Matz --- lib/librte_kvargs/rte_kvargs.c | 4 ++++ lib/librte_kvargs/rte_kvargs.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 8bc1e46117..c2dd051336 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -174,8 +174,12 @@ rte_kvargs_process(const struct rte_kvargs *kvlist, void rte_kvargs_free(struct rte_kvargs *kvlist) { + if (!kvlist) + return; + if (kvlist->str != NULL) free(kvlist->str); + free(kvlist); } diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index ef4efabfb5..ae9ae79f21 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -115,7 +115,8 @@ void rte_kvargs_free(struct rte_kvargs *kvlist); * * For each key/value association that matches the given key, calls the * handler function with the for a given arg_name passing the value on the - * dictionary for that key and a given extra argument. + * dictionary for that key and a given extra argument. If *kvlist* is NULL + * function does nothing. * * @param kvlist * The rte_kvargs structure -- 2.20.1