diff mbox series

app/testpmd: fix memory leak for dscp table

Message ID 20220628132916.1284235-1-jasvinder.singh@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Andrew Rybchenko
Headers show
Series app/testpmd: fix memory leak for dscp table | expand

Checks

Context Check Description
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Singh, Jasvinder June 28, 2022, 1:29 p.m. UTC
This patch fixes memory leak reported by coverity.

Coverity issue: 379220
Fixes: 9f5488e326d3 ("app/testpmd: support different input color method")

Cc: stable@dpdk.org

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 app/test-pmd/cmdline_mtr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Morrissey, Sean June 29, 2022, 3:37 p.m. UTC | #1
Reviewed-by: Sean Morrissey <sean.morrissey@intel.com>

Thanks.

On 28/06/2022 14:29, Jasvinder Singh wrote:
> This patch fixes memory leak reported by coverity.
>
> Coverity issue: 379220
> Fixes: 9f5488e326d3 ("app/testpmd: support different input color method")
>
> Cc: stable@dpdk.org
>
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> ---
>   app/test-pmd/cmdline_mtr.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
> index b92e66cedb..833273da0d 100644
> --- a/app/test-pmd/cmdline_mtr.c
> +++ b/app/test-pmd/cmdline_mtr.c
> @@ -131,8 +131,10 @@ parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
>   	/* Allocate memory for vlan table */
>   	vlan = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
>   		sizeof(enum rte_color));
> -	if (vlan == NULL)
> +	if (vlan == NULL) {
> +		free(*dscp_table);
>   		return -1;
> +	}
>   
>   	i = 0;
>   	while (1) {
> @@ -144,6 +146,7 @@ parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
>   			vlan[i++] = RTE_COLOR_RED;
>   		else {
>   			free(vlan);
> +			free(*dscp_table);
>   			return -1;
>   		}
>   		if (i == MAX_VLAN_TABLE_ENTRIES)
> @@ -152,6 +155,7 @@ parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
>   		token = strtok_r(str, PARSE_DELIMITER, &str);
>   		if (token == NULL) {
>   			free(vlan);
> +			free(*dscp_table);
>   			return -1;
>   		}
>   	}
Singh, Aman Deep June 29, 2022, 4:53 p.m. UTC | #2
Hi Jasvinder,

Thanks for the patch.


On 6/29/2022 9:07 PM, Morrissey, Sean wrote:
> Reviewed-by: Sean Morrissey <sean.morrissey@intel.com>
>
> Thanks.
>
> On 28/06/2022 14:29, Jasvinder Singh wrote:
>> This patch fixes memory leak reported by coverity.
>>
>> Coverity issue: 379220
>> Fixes: 9f5488e326d3 ("app/testpmd: support different input color 
>> method")
>>
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
>> ---
>>   app/test-pmd/cmdline_mtr.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
>> index b92e66cedb..833273da0d 100644
>> --- a/app/test-pmd/cmdline_mtr.c
>> +++ b/app/test-pmd/cmdline_mtr.c
>> @@ -131,8 +131,10 @@ parse_input_color_table_entries(char *str, enum 
>> rte_color **dscp_table,
>>       /* Allocate memory for vlan table */
>>       vlan = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
>>           sizeof(enum rte_color));
>> -    if (vlan == NULL)
>> +    if (vlan == NULL) {
>> +        free(*dscp_table);
>>           return -1;
>> +    }

Did we miss one return at line 129, or is it not required-

	token = strtok_r(str, PARSE_DELIMITER, &str);
	if (token == NULL)
		return 0;

>>         i = 0;
>>       while (1) {
>> @@ -144,6 +146,7 @@ parse_input_color_table_entries(char *str, enum 
>> rte_color **dscp_table,
>>               vlan[i++] = RTE_COLOR_RED;
>>           else {
>>               free(vlan);
>> +            free(*dscp_table);
>>               return -1;
>>           }
>>           if (i == MAX_VLAN_TABLE_ENTRIES)
>> @@ -152,6 +155,7 @@ parse_input_color_table_entries(char *str, enum 
>> rte_color **dscp_table,
>>           token = strtok_r(str, PARSE_DELIMITER, &str);
>>           if (token == NULL) {
>>               free(vlan);
>> +            free(*dscp_table);
>>               return -1;
>>           }
>>       }
Singh, Jasvinder June 29, 2022, 5:24 p.m. UTC | #3
> -----Original Message-----
> From: Singh, Aman Deep <aman.deep.singh@intel.com>
> Sent: Wednesday, June 29, 2022 5:53 PM
> To: Morrissey, Sean <sean.morrissey@intel.com>; Singh, Jasvinder
> <jasvinder.singh@intel.com>; dev@dpdk.org
> Cc: Zhang, Yuying <yuying.zhang@intel.com>; stable@dpdk.org
> Subject: Re: [PATCH] app/testpmd: fix memory leak for dscp table
> 
> Hi Jasvinder,
> 
> Thanks for the patch.
> 
> 
> On 6/29/2022 9:07 PM, Morrissey, Sean wrote:
> > Reviewed-by: Sean Morrissey <sean.morrissey@intel.com>
> >
> > Thanks.
> >
> > On 28/06/2022 14:29, Jasvinder Singh wrote:
> >> This patch fixes memory leak reported by coverity.
> >>
> >> Coverity issue: 379220
> >> Fixes: 9f5488e326d3 ("app/testpmd: support different input color
> >> method")
> >>
> >> Cc: stable@dpdk.org
> >>
> >> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> >> ---
> >>   app/test-pmd/cmdline_mtr.c | 6 +++++-
> >>   1 file changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
> >> index b92e66cedb..833273da0d 100644
> >> --- a/app/test-pmd/cmdline_mtr.c
> >> +++ b/app/test-pmd/cmdline_mtr.c
> >> @@ -131,8 +131,10 @@ parse_input_color_table_entries(char *str, enum
> >> rte_color **dscp_table,
> >>       /* Allocate memory for vlan table */
> >>       vlan = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
> >>           sizeof(enum rte_color));
> >> -    if (vlan == NULL)
> >> +    if (vlan == NULL) {
> >> +        free(*dscp_table);
> >>           return -1;
> >> +    }
> 
> Did we miss one return at line 129, or is it not required-
> 
> 	token = strtok_r(str, PARSE_DELIMITER, &str);
> 	if (token == NULL)
> 		return 0;
> 
No need to free the allocated memory on successful return from the function.
Singh, Aman Deep June 29, 2022, 5:30 p.m. UTC | #4
On 6/28/2022 6:59 PM, Jasvinder Singh wrote:
> This patch fixes memory leak reported by coverity.
>
> Coverity issue: 379220
> Fixes: 9f5488e326d3 ("app/testpmd: support different input color method")
>
> Cc: stable@dpdk.org
>
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>

Acked-by: Aman Singh<aman.deep.singh@intel.com>
Andrew Rybchenko July 6, 2022, 2:32 p.m. UTC | #5
In summary: dscp -> DSCP

On 6/29/22 20:30, Singh, Aman Deep wrote:
> 
> 
> On 6/28/2022 6:59 PM, Jasvinder Singh wrote:
>> This patch fixes memory leak reported by coverity.
>>
>> Coverity issue: 379220
>> Fixes: 9f5488e326d3 ("app/testpmd: support different input color method")
>>
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> 
> Acked-by: Aman Singh<aman.deep.singh@intel.com>
> 

Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Andrew Rybchenko July 7, 2022, 12:39 p.m. UTC | #6
On 7/6/22 17:32, Andrew Rybchenko wrote:
> In summary: dscp -> DSCP
> 
> On 6/29/22 20:30, Singh, Aman Deep wrote:
>>
>>
>> On 6/28/2022 6:59 PM, Jasvinder Singh wrote:
>>> This patch fixes memory leak reported by coverity.
>>>
>>> Coverity issue: 379220
>>> Fixes: 9f5488e326d3 ("app/testpmd: support different input color 
>>> method")
>>>
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
>>
>> Acked-by: Aman Singh<aman.deep.singh@intel.com>
>>
> 
> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Applied to dpdk-next-net/main, thanks.
diff mbox series

Patch

diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
index b92e66cedb..833273da0d 100644
--- a/app/test-pmd/cmdline_mtr.c
+++ b/app/test-pmd/cmdline_mtr.c
@@ -131,8 +131,10 @@  parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
 	/* Allocate memory for vlan table */
 	vlan = (enum rte_color *)malloc(MAX_VLAN_TABLE_ENTRIES *
 		sizeof(enum rte_color));
-	if (vlan == NULL)
+	if (vlan == NULL) {
+		free(*dscp_table);
 		return -1;
+	}
 
 	i = 0;
 	while (1) {
@@ -144,6 +146,7 @@  parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
 			vlan[i++] = RTE_COLOR_RED;
 		else {
 			free(vlan);
+			free(*dscp_table);
 			return -1;
 		}
 		if (i == MAX_VLAN_TABLE_ENTRIES)
@@ -152,6 +155,7 @@  parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
 		token = strtok_r(str, PARSE_DELIMITER, &str);
 		if (token == NULL) {
 			free(vlan);
+			free(*dscp_table);
 			return -1;
 		}
 	}