null: fix memory leak of kvargs
authorTetsuya Mukawa <mukawa@igel.co.jp>
Tue, 17 Mar 2015 04:12:41 +0000 (13:12 +0900)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 17 Mar 2015 21:58:21 +0000 (22:58 +0100)
'struct rte_kvargs' is allocated in rte_kvargs_parse(), and should be
freed with rte_kvargs_free().

Reported-by: John Mcnamara <john.mcnamara@intel.com>
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
lib/librte_pmd_null/rte_eth_null.c

index f49d686..8fe1a2d 100644 (file)
@@ -506,7 +506,7 @@ rte_pmd_null_devinit(const char *name, const char *params)
        unsigned numa_node;
        unsigned packet_size = default_packet_size;
        unsigned packet_copy = default_packet_copy;
-       struct rte_kvargs *kvlist;
+       struct rte_kvargs *kvlist = NULL;
        int ret;
 
        if (name == NULL)
@@ -527,7 +527,7 @@ rte_pmd_null_devinit(const char *name, const char *params)
                                        ETH_NULL_PACKET_SIZE_ARG,
                                        &get_packet_size_arg, &packet_size);
                        if (ret < 0)
-                               return -1;
+                               goto free_kvlist;
                }
 
                if (rte_kvargs_count(kvlist, ETH_NULL_PACKET_COPY_ARG) == 1) {
@@ -536,7 +536,7 @@ rte_pmd_null_devinit(const char *name, const char *params)
                                        ETH_NULL_PACKET_COPY_ARG,
                                        &get_packet_copy_arg, &packet_copy);
                        if (ret < 0)
-                               return -1;
+                               goto free_kvlist;
                }
        }
 
@@ -544,7 +544,12 @@ rte_pmd_null_devinit(const char *name, const char *params)
                        "packet copy is %s\n", packet_size,
                        packet_copy ? "enabled" : "disabled");
 
-       return eth_dev_null_create(name, numa_node, packet_size, packet_copy);
+       ret = eth_dev_null_create(name, numa_node, packet_size, packet_copy);
+
+free_kvlist:
+       if (kvlist)
+               rte_kvargs_free(kvlist);
+       return ret;
 }
 
 static int