app/testpmd: fix action destruction memory leak

Message ID 20221117085537.24372-1-suanmingm@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series app/testpmd: fix action destruction memory leak |

Checks

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

Commit Message

Suanming Mou Nov. 17, 2022, 8:55 a.m. UTC
  In case action handle destroy fails, the job memory was not freed
properly. This commit fixes the possible memory leak in the action
handle destruction failed case.

Fixes: c9dc03840873 ("ethdev: add indirect action async query")

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
---
 app/test-pmd/config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

David Marchand Nov. 17, 2022, 11:41 a.m. UTC | #1
On Thu, Nov 17, 2022 at 9:56 AM Suanming Mou <suanmingm@nvidia.com> wrote:
>
> In case action handle destroy fails, the job memory was not freed
> properly. This commit fixes the possible memory leak in the action
> handle destruction failed case.
>
> Fixes: c9dc03840873 ("ethdev: add indirect action async query")
>

Reported-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>

LGTM.
Reviewed-by: David Marchand <david.marchand@redhat.com>

Thanks.
  
Ferruh Yigit Nov. 18, 2022, 10:40 a.m. UTC | #2
On 11/17/2022 8:55 AM, Suanming Mou wrote:
> In case action handle destroy fails, the job memory was not freed
> properly. This commit fixes the possible memory leak in the action
> handle destruction failed case.
> 
> Fixes: c9dc03840873 ("ethdev: add indirect action async query")
> 
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> ---
>  app/test-pmd/config.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index 982549ffed..719bdd4261 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -2873,9 +2873,9 @@ port_queue_action_handle_destroy(portid_t port_id,
>  			job->type = QUEUE_JOB_TYPE_ACTION_DESTROY;
>  			job->pia = pia;
>  
> -			if (pia->handle &&
> -			    rte_flow_async_action_handle_destroy(port_id,
> +			if (rte_flow_async_action_handle_destroy(port_id,

Why 'pia->handle' check removed, was it unnecessary to check it at first
place?

>  				queue_id, &attr, pia->handle, job, &error)) {
> +				free(job);
>  				ret = port_flow_complain(&error);
>  				continue;
>  			}

Just to double check, when this if branch not taken,
'rte_flow_async_action_handle_destroy()' not failed case, testpmd
'port_queue_flow_pull()' functions frees the 'job', right?
  
Suanming Mou Nov. 18, 2022, 12:21 p.m. UTC | #3
Hi,

> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Friday, November 18, 2022 6:40 PM
> To: Suanming Mou <suanmingm@nvidia.com>; david.marchand@redhat.com;
> Aman Singh <aman.deep.singh@intel.com>; Yuying Zhang
> <yuying.zhang@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [PATCH] app/testpmd: fix action destruction memory leak
> 
> On 11/17/2022 8:55 AM, Suanming Mou wrote:
> > In case action handle destroy fails, the job memory was not freed
> > properly. This commit fixes the possible memory leak in the action
> > handle destruction failed case.
> >
> > Fixes: c9dc03840873 ("ethdev: add indirect action async query")
> >
> > Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> > ---
> >  app/test-pmd/config.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index
> > 982549ffed..719bdd4261 100644
> > --- a/app/test-pmd/config.c
> > +++ b/app/test-pmd/config.c
> > @@ -2873,9 +2873,9 @@ port_queue_action_handle_destroy(portid_t
> port_id,
> >  			job->type = QUEUE_JOB_TYPE_ACTION_DESTROY;
> >  			job->pia = pia;
> >
> > -			if (pia->handle &&
> > -			    rte_flow_async_action_handle_destroy(port_id,
> > +			if (rte_flow_async_action_handle_destroy(port_id,
> 
> Why 'pia->handle' check removed, was it unnecessary to check it at first place?
> 
> >  				queue_id, &attr, pia->handle, job, &error)) {
> > +				free(job);
> >  				ret = port_flow_complain(&error);
> >  				continue;
> >  			}
> 
> Just to double check, when this if branch not taken,
> 'rte_flow_async_action_handle_destroy()' not failed case, testpmd
> 'port_queue_flow_pull()' functions frees the 'job', right?

Yes, port_queue_flow_pull() will free the 'job'.
  
Ferruh Yigit Nov. 18, 2022, 3:19 p.m. UTC | #4
On 11/18/2022 12:21 PM, Suanming Mou wrote:
> Hi,
> 
>> -----Original Message-----
>> From: Ferruh Yigit <ferruh.yigit@amd.com>
>> Sent: Friday, November 18, 2022 6:40 PM
>> To: Suanming Mou <suanmingm@nvidia.com>; david.marchand@redhat.com;
>> Aman Singh <aman.deep.singh@intel.com>; Yuying Zhang
>> <yuying.zhang@intel.com>
>> Cc: dev@dpdk.org
>> Subject: Re: [PATCH] app/testpmd: fix action destruction memory leak
>>
>> On 11/17/2022 8:55 AM, Suanming Mou wrote:
>>> In case action handle destroy fails, the job memory was not freed
>>> properly. This commit fixes the possible memory leak in the action
>>> handle destruction failed case.
>>>
>>> Fixes: c9dc03840873 ("ethdev: add indirect action async query")
>>>
>>> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
>>> ---
>>>  app/test-pmd/config.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index
>>> 982549ffed..719bdd4261 100644
>>> --- a/app/test-pmd/config.c
>>> +++ b/app/test-pmd/config.c
>>> @@ -2873,9 +2873,9 @@ port_queue_action_handle_destroy(portid_t
>> port_id,
>>>  			job->type = QUEUE_JOB_TYPE_ACTION_DESTROY;
>>>  			job->pia = pia;
>>>
>>> -			if (pia->handle &&
>>> -			    rte_flow_async_action_handle_destroy(port_id,
>>> +			if (rte_flow_async_action_handle_destroy(port_id,
>>
>> Why 'pia->handle' check removed, was it unnecessary to check it at first place?

This seems already discussed and agreed in other thread, so proceeding.

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 982549ffed..719bdd4261 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2873,9 +2873,9 @@  port_queue_action_handle_destroy(portid_t port_id,
 			job->type = QUEUE_JOB_TYPE_ACTION_DESTROY;
 			job->pia = pia;
 
-			if (pia->handle &&
-			    rte_flow_async_action_handle_destroy(port_id,
+			if (rte_flow_async_action_handle_destroy(port_id,
 				queue_id, &attr, pia->handle, job, &error)) {
+				free(job);
 				ret = port_flow_complain(&error);
 				continue;
 			}