Message ID | 20200419073754.72967-1-chenzefeng2@huawei.com |
---|---|
State | Superseded |
Headers | show |
Series | malloc: fix memleak in function muntrace | expand |
* chenzefeng: > diff --git a/malloc/mtrace.c b/malloc/mtrace.c > index 7e7719df97..0b92106e6e 100644 > --- a/malloc/mtrace.c > +++ b/malloc/mtrace.c > @@ -365,4 +365,6 @@ muntrace (void) > > fprintf (f, "= End\n"); > fclose (f); > + if (mtb != NULL) > + free (mtb); > } I don't think this will build. The global variable is called malloc_trace_buffer.
* Florian Weimer: >* chenzefeng: >> diff --git a/malloc/mtrace.c b/malloc/mtrace.c index >> 7e7719df97..0b92106e6e 100644 >> --- a/malloc/mtrace.c >> +++ b/malloc/mtrace.c >> @@ -365,4 +365,6 @@ muntrace (void) >> >> fprintf (f, "= End\n"); >> fclose (f); >> + if (mtb != NULL) >> + free (mtb); >> } >I don't think this will build. The global variable is called malloc_trace_buffer. I am sorry, I had not got the correctly patch from local file. I commit it again, thanks for you review.
diff --git a/malloc/mtrace.c b/malloc/mtrace.c index 7e7719df97..0b92106e6e 100644 --- a/malloc/mtrace.c +++ b/malloc/mtrace.c @@ -365,4 +365,6 @@ muntrace (void) fprintf (f, "= End\n"); fclose (f); + if (mtb != NULL) + free (mtb); }
when we call functons as follow: mtrace(); ... muntrace(); It would cause memleak, for the mtrace malloc some memory: mtd = malloc(TRACE_BUFFER_SIZE); and it would not be free. Therefor it should be freed in muntrace. Signed-off-by: chenzefeng <chenzefeng2@huawei.com> --- malloc/mtrace.c | 2 ++ 1 file changed, 2 insertions(+)