pcap: 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_pcap/rte_eth_pcap.c

index 5e94930..204ae68 100644 (file)
@@ -888,12 +888,13 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
                ret = rte_kvargs_process(kvlist, ETH_PCAP_IFACE_ARG,
                                &open_rx_tx_iface, &pcaps);
                if (ret < 0)
-                       return -1;
+                       goto free_kvlist;
                dumpers.pcaps[0] = pcaps.pcaps[0];
                dumpers.names[0] = pcaps.names[0];
                dumpers.types[0] = pcaps.types[0];
-               return rte_eth_from_pcaps(name, &pcaps, 1, &dumpers, 1,
+               ret = rte_eth_from_pcaps(name, &pcaps, 1, &dumpers, 1,
                                numa_node, kvlist, 1);
+               goto free_kvlist;
        }
 
        /*
@@ -911,7 +912,7 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
        }
 
        if (ret < 0)
-               return -1;
+               goto free_kvlist;
 
        /*
         * We check whether we want to open a TX stream to a real NIC or a
@@ -930,15 +931,18 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
        }
 
        if (ret < 0)
-               return -1;
+               goto free_kvlist;
 
        if (using_dumpers)
-               return rte_eth_from_pcaps_n_dumpers(name, &pcaps, pcaps.num_of_rx,
+               ret = rte_eth_from_pcaps_n_dumpers(name, &pcaps, pcaps.num_of_rx,
                                &dumpers, dumpers.num_of_tx, numa_node, kvlist);
-
-       return rte_eth_from_pcaps(name, &pcaps, pcaps.num_of_rx, &dumpers,
+       else
+               ret = rte_eth_from_pcaps(name, &pcaps, pcaps.num_of_rx, &dumpers,
                        dumpers.num_of_tx, numa_node, kvlist, 0);
 
+free_kvlist:
+       rte_kvargs_free(kvlist);
+       return ret;
 }
 
 static int