DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs'
@ 2015-03-16  3:42 Tetsuya Mukawa
  2015-03-16 10:47 ` Neil Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tetsuya Mukawa @ 2015-03-16  3:42 UTC (permalink / raw)
  To: dev

'struct rte_kvargs' is allocated in rte_kvargs_parse(), and should be
freed with rte_kvargs_free().
This patch fixes memory leaks of 'struct rte_kvargs' in below PMDs.
 - pcap PMD
 - af_packet PMD
 - null PMD

Reported-by: Mcnamara, John <john.mcnamara@intel.com>
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c |  5 ++++-
 lib/librte_pmd_null/rte_eth_null.c           | 13 +++++++++----
 lib/librte_pmd_pcap/rte_eth_pcap.c           | 18 +++++++++++-------
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
index 80e9bdf..7c3c6a9 100644
--- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
+++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
@@ -823,12 +823,15 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
 		ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
 		                         &open_packet_iface, &sockfd);
 		if (ret < 0)
-			return -1;
+			goto free_kvlist_then_return;
 	}
 
 	ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
 	close(sockfd); /* no longer needed */
 
+free_kvlist_then_return:
+	rte_kvargs_free(kvlist);
+
 	if (ret < 0)
 		return -1;
 
diff --git a/lib/librte_pmd_null/rte_eth_null.c b/lib/librte_pmd_null/rte_eth_null.c
index f49d686..86307eb 100644
--- a/lib/librte_pmd_null/rte_eth_null.c
+++ b/lib/librte_pmd_null/rte_eth_null.c
@@ -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_then_return;
 		}
 
 		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_then_return;
 		}
 	}
 
@@ -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_then_return:
+	if (kvlist)
+		rte_kvargs_free(kvlist);
+	return ret;
 }
 
 static int
diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
index 5e94930..de15fb3 100644
--- a/lib/librte_pmd_pcap/rte_eth_pcap.c
+++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
@@ -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_then_return;
 		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_then_return;
 	}
 
 	/*
@@ -911,7 +912,7 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
 	}
 
 	if (ret < 0)
-		return -1;
+		goto free_kvlist_then_return;
 
 	/*
 	 * 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_then_return;
 
 	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_then_return:
+	rte_kvargs_free(kvlist);
+	return ret;
 }
 
 static int
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs'
  2015-03-16  3:42 [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs' Tetsuya Mukawa
@ 2015-03-16 10:47 ` Neil Horman
  2015-03-17  3:53   ` Tetsuya Mukawa
  2015-03-16 11:07 ` Mcnamara, John
  2015-03-17  4:12 ` [dpdk-dev] [PATCH v2] pcap, " Tetsuya Mukawa
  2 siblings, 1 reply; 7+ messages in thread
From: Neil Horman @ 2015-03-16 10:47 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Mar 16, 2015 at 12:42:56PM +0900, Tetsuya Mukawa wrote:
> 'struct rte_kvargs' is allocated in rte_kvargs_parse(), and should be
> freed with rte_kvargs_free().
> This patch fixes memory leaks of 'struct rte_kvargs' in below PMDs.
>  - pcap PMD
>  - af_packet PMD
>  - null PMD
> 
> Reported-by: Mcnamara, John <john.mcnamara@intel.com>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Typically, you should limit your goto tags to something more minimalist that
describes the one thing you want to unwind at the label.  As it stands here,  if
somone wants to add some code after this label, the label either becomes
incorrect, or you need to fix up the label name to match.  But I suppose that
can be corrected later.

Acked-by: Neil Horman <nhorman@tuxdriver.com>


> ---
>  lib/librte_pmd_af_packet/rte_eth_af_packet.c |  5 ++++-
>  lib/librte_pmd_null/rte_eth_null.c           | 13 +++++++++----
>  lib/librte_pmd_pcap/rte_eth_pcap.c           | 18 +++++++++++-------
>  3 files changed, 24 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> index 80e9bdf..7c3c6a9 100644
> --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> @@ -823,12 +823,15 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
>  		ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
>  		                         &open_packet_iface, &sockfd);
>  		if (ret < 0)
> -			return -1;
> +			goto free_kvlist_then_return;
>  	}
>  
>  	ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
>  	close(sockfd); /* no longer needed */
>  
> +free_kvlist_then_return:
> +	rte_kvargs_free(kvlist);
> +
>  	if (ret < 0)
>  		return -1;
>  
> diff --git a/lib/librte_pmd_null/rte_eth_null.c b/lib/librte_pmd_null/rte_eth_null.c
> index f49d686..86307eb 100644
> --- a/lib/librte_pmd_null/rte_eth_null.c
> +++ b/lib/librte_pmd_null/rte_eth_null.c
> @@ -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_then_return;
>  		}
>  
>  		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_then_return;
>  		}
>  	}
>  
> @@ -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_then_return:
> +	if (kvlist)
> +		rte_kvargs_free(kvlist);
> +	return ret;
>  }
>  
>  static int
> diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
> index 5e94930..de15fb3 100644
> --- a/lib/librte_pmd_pcap/rte_eth_pcap.c
> +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
> @@ -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_then_return;
>  		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_then_return;
>  	}
>  
>  	/*
> @@ -911,7 +912,7 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
>  	}
>  
>  	if (ret < 0)
> -		return -1;
> +		goto free_kvlist_then_return;
>  
>  	/*
>  	 * 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_then_return;
>  
>  	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_then_return:
> +	rte_kvargs_free(kvlist);
> +	return ret;
>  }
>  
>  static int
> -- 
> 1.9.1
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs'
  2015-03-16  3:42 [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs' Tetsuya Mukawa
  2015-03-16 10:47 ` Neil Horman
@ 2015-03-16 11:07 ` Mcnamara, John
  2015-03-17  3:54   ` Tetsuya Mukawa
  2015-03-17  4:12 ` [dpdk-dev] [PATCH v2] pcap, " Tetsuya Mukawa
  2 siblings, 1 reply; 7+ messages in thread
From: Mcnamara, John @ 2015-03-16 11:07 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Monday, March 16, 2015 3:43 AM
> To: dev@dpdk.org
> Cc: Mcnamara, John; Tetsuya Mukawa
> Subject: [PATCH] pcap,af_packet,null: Fix memory leaks of 'struct
> rte_kvargs'
>
>  lib/librte_pmd_af_packet/rte_eth_af_packet.c |  5 ++++-
>  lib/librte_pmd_null/rte_eth_null.c           | 13 +++++++++----
>  lib/librte_pmd_pcap/rte_eth_pcap.c           | 18 +++++++++++-------
>  3 files changed, 24 insertions(+), 12 deletions(-)

Hi,

There is already a patch for the af_packet kvlist leak in review:

    http://dpdk.org/ml/archives/dev/2015-March/015049.html

The eth_null and pcap issues haven't been addressed yet though.

John

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs'
  2015-03-16 10:47 ` Neil Horman
@ 2015-03-17  3:53   ` Tetsuya Mukawa
  0 siblings, 0 replies; 7+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  3:53 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

On 2015/03/16 19:47, Neil Horman wrote:
> On Mon, Mar 16, 2015 at 12:42:56PM +0900, Tetsuya Mukawa wrote:
>> 'struct rte_kvargs' is allocated in rte_kvargs_parse(), and should be
>> freed with rte_kvargs_free().
>> This patch fixes memory leaks of 'struct rte_kvargs' in below PMDs.
>>  - pcap PMD
>>  - af_packet PMD
>>  - null PMD
>>
>> Reported-by: Mcnamara, John <john.mcnamara@intel.com>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Typically, you should limit your goto tags to something more minimalist that
> describes the one thing you want to unwind at the label.  As it stands here,  if
> somone wants to add some code after this label, the label either becomes
> incorrect, or you need to fix up the label name to match.  But I suppose that
> can be corrected later.

Hi Neil,

I appreciate for your suggestion.
I will need to remove af_packet fixing and submit the patch again.
So I will follow your suggestion in the next patch.

Thanks,
Tetsuya

> Acked-by: Neil Horman <nhorman@tuxdriver.com>
>
>
>> ---
>>  lib/librte_pmd_af_packet/rte_eth_af_packet.c |  5 ++++-
>>  lib/librte_pmd_null/rte_eth_null.c           | 13 +++++++++----
>>  lib/librte_pmd_pcap/rte_eth_pcap.c           | 18 +++++++++++-------
>>  3 files changed, 24 insertions(+), 12 deletions(-)
>>
>> diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> index 80e9bdf..7c3c6a9 100644
>> --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> @@ -823,12 +823,15 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
>>  		ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
>>  		                         &open_packet_iface, &sockfd);
>>  		if (ret < 0)
>> -			return -1;
>> +			goto free_kvlist_then_return;
>>  	}
>>  
>>  	ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
>>  	close(sockfd); /* no longer needed */
>>  
>> +free_kvlist_then_return:
>> +	rte_kvargs_free(kvlist);
>> +
>>  	if (ret < 0)
>>  		return -1;
>>  
>> diff --git a/lib/librte_pmd_null/rte_eth_null.c b/lib/librte_pmd_null/rte_eth_null.c
>> index f49d686..86307eb 100644
>> --- a/lib/librte_pmd_null/rte_eth_null.c
>> +++ b/lib/librte_pmd_null/rte_eth_null.c
>> @@ -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_then_return;
>>  		}
>>  
>>  		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_then_return;
>>  		}
>>  	}
>>  
>> @@ -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_then_return:
>> +	if (kvlist)
>> +		rte_kvargs_free(kvlist);
>> +	return ret;
>>  }
>>  
>>  static int
>> diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
>> index 5e94930..de15fb3 100644
>> --- a/lib/librte_pmd_pcap/rte_eth_pcap.c
>> +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
>> @@ -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_then_return;
>>  		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_then_return;
>>  	}
>>  
>>  	/*
>> @@ -911,7 +912,7 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
>>  	}
>>  
>>  	if (ret < 0)
>> -		return -1;
>> +		goto free_kvlist_then_return;
>>  
>>  	/*
>>  	 * 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_then_return;
>>  
>>  	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_then_return:
>> +	rte_kvargs_free(kvlist);
>> +	return ret;
>>  }
>>  
>>  static int
>> -- 
>> 1.9.1
>>
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs'
  2015-03-16 11:07 ` Mcnamara, John
@ 2015-03-17  3:54   ` Tetsuya Mukawa
  0 siblings, 0 replies; 7+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  3:54 UTC (permalink / raw)
  To: Mcnamara, John, dev

On 2015/03/16 20:07, Mcnamara, John wrote:
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Monday, March 16, 2015 3:43 AM
>> To: dev@dpdk.org
>> Cc: Mcnamara, John; Tetsuya Mukawa
>> Subject: [PATCH] pcap,af_packet,null: Fix memory leaks of 'struct
>> rte_kvargs'
>>
>>  lib/librte_pmd_af_packet/rte_eth_af_packet.c |  5 ++++-
>>  lib/librte_pmd_null/rte_eth_null.c           | 13 +++++++++----
>>  lib/librte_pmd_pcap/rte_eth_pcap.c           | 18 +++++++++++-------
>>  3 files changed, 24 insertions(+), 12 deletions(-)
> Hi,
>
> There is already a patch for the af_packet kvlist leak in review:
>
>     http://dpdk.org/ml/archives/dev/2015-March/015049.html
>
> The eth_null and pcap issues haven't been addressed yet though.
>
> John
>
>

Hi John,

Thanks, I will remove af_packet fixinig, and submit it again.

Tetsuya

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [dpdk-dev] [PATCH v2] pcap, null: Fix memory leaks of 'struct rte_kvargs'
  2015-03-16  3:42 [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs' Tetsuya Mukawa
  2015-03-16 10:47 ` Neil Horman
  2015-03-16 11:07 ` Mcnamara, John
@ 2015-03-17  4:12 ` Tetsuya Mukawa
  2015-03-17 21:58   ` Thomas Monjalon
  2 siblings, 1 reply; 7+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  4:12 UTC (permalink / raw)
  To: dev

'struct rte_kvargs' is allocated in rte_kvargs_parse(), and should be
freed with rte_kvargs_free().
This patch fixes memory leaks of 'struct rte_kvargs' in below PMDs.
 - pcap PMD
 - null PMD

Reported-by: Mcnamara, John <john.mcnamara@intel.com>
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_pmd_null/rte_eth_null.c | 13 +++++++++----
 lib/librte_pmd_pcap/rte_eth_pcap.c | 18 +++++++++++-------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/librte_pmd_null/rte_eth_null.c b/lib/librte_pmd_null/rte_eth_null.c
index f49d686..8fe1a2d 100644
--- a/lib/librte_pmd_null/rte_eth_null.c
+++ b/lib/librte_pmd_null/rte_eth_null.c
@@ -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
diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
index 5e94930..204ae68 100644
--- a/lib/librte_pmd_pcap/rte_eth_pcap.c
+++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
@@ -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
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-dev] [PATCH v2] pcap, null: Fix memory leaks of 'struct rte_kvargs'
  2015-03-17  4:12 ` [dpdk-dev] [PATCH v2] pcap, " Tetsuya Mukawa
@ 2015-03-17 21:58   ` Thomas Monjalon
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2015-03-17 21:58 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

2015-03-17 13:12, Tetsuya Mukawa:
> 'struct rte_kvargs' is allocated in rte_kvargs_parse(), and should be
> freed with rte_kvargs_free().
> This patch fixes memory leaks of 'struct rte_kvargs' in below PMDs.
>  - pcap PMD
>  - null PMD
> 
> Reported-by: Mcnamara, John <john.mcnamara@intel.com>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Split and applied, thanks

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-17 21:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16  3:42 [dpdk-dev] [PATCH] pcap, af_packet, null: Fix memory leaks of 'struct rte_kvargs' Tetsuya Mukawa
2015-03-16 10:47 ` Neil Horman
2015-03-17  3:53   ` Tetsuya Mukawa
2015-03-16 11:07 ` Mcnamara, John
2015-03-17  3:54   ` Tetsuya Mukawa
2015-03-17  4:12 ` [dpdk-dev] [PATCH v2] pcap, " Tetsuya Mukawa
2015-03-17 21:58   ` Thomas Monjalon

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git