[lttng-tools] Fix: Free new_chunk on error
diff mbox series

Message ID 20190920144730.163268-1-jonathan.rajotte-julien@efficios.com
State Accepted, archived
Headers show
Series
  • [lttng-tools] Fix: Free new_chunk on error
Related show

Commit Message

Jonathan Rajotte Sept. 20, 2019, 2:47 p.m. UTC
Fixes coverity #1405775

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 src/common/trace-chunk.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jérémie Galarneau Sept. 20, 2019, 9:34 p.m. UTC | #1
Merged in master and stable-2.11.

On Fri, Sep 20, 2019 at 10:47:30AM -0400, Jonathan Rajotte wrote:
> Fixes coverity #1405775
> 
> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
> ---
>  src/common/trace-chunk.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c
> index 6770bd982..bad993bea 100644
> --- a/src/common/trace-chunk.c
> +++ b/src/common/trace-chunk.c
> @@ -367,6 +367,8 @@ end:
>  	return new_chunk;
>  error_unlock:
>  	pthread_mutex_unlock(&source_chunk->lock);
> +	lttng_trace_chunk_fini(new_chunk);
> +	free(new_chunk);

Changed this to lttng_trace_chunk_put(), which will drop the only
existing reference to `new_chunk` and perform the equivalent
operations to what you proposed here.

Thanks!
J?r?mie

>  	return NULL;
>  }
>  
> -- 
> 2.17.1
>
Jonathan Rajotte Sept. 20, 2019, 9:37 p.m. UTC | #2
On Fri, Sep 20, 2019 at 05:34:26PM -0400, J?r?mie Galarneau wrote:
> Merged in master and stable-2.11.
> 
> On Fri, Sep 20, 2019 at 10:47:30AM -0400, Jonathan Rajotte wrote:
> > Fixes coverity #1405775
> > 
> > Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
> > ---
> >  src/common/trace-chunk.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c
> > index 6770bd982..bad993bea 100644
> > --- a/src/common/trace-chunk.c
> > +++ b/src/common/trace-chunk.c
> > @@ -367,6 +367,8 @@ end:
> >  	return new_chunk;
> >  error_unlock:
> >  	pthread_mutex_unlock(&source_chunk->lock);
> > +	lttng_trace_chunk_fini(new_chunk);
> > +	free(new_chunk);
> 
> Changed this to lttng_trace_chunk_put(), which will drop the only
> existing reference to `new_chunk` and perform the equivalent
> operations to what you proposed here.

Okai, I saw a similar pattern somewhere in the file. Might want to check if the
same can be applied there.

> 
> Thanks!
> J?r?mie
> 
> >  	return NULL;
> >  }
> >  
> > -- 
> > 2.17.1
> >
Jonathan Rajotte Sept. 20, 2019, 9:42 p.m. UTC | #3
> 
> Okai, I saw a similar pattern somewhere in the file. Might want to check if the
> same can be applied there.

Nevermind it is in the release code.

> 
> > 
> > Thanks!
> > J?r?mie
> > 
> > >  	return NULL;
> > >  }
> > >  
> > > -- 
> > > 2.17.1
> > > 
> 
> -- 
> Jonathan Rajotte-Julien
> EfficiOS
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Patch
diff mbox series

diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c
index 6770bd982..bad993bea 100644
--- a/src/common/trace-chunk.c
+++ b/src/common/trace-chunk.c
@@ -367,6 +367,8 @@  end:
 	return new_chunk;
 error_unlock:
 	pthread_mutex_unlock(&source_chunk->lock);
+	lttng_trace_chunk_fini(new_chunk);
+	free(new_chunk);
 	return NULL;
 }