public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: chenzefeng <chenzefeng2@huawei.com>
To: <libc-alpha@sourceware.org>, <fw@deneb.enyo.de>, <dj@redhat.com>,
	<zackw@panix.com>
Cc: <liucheng32@huawei.com>, <chenzefeng2@huawei.com>,
	<zengweilin@huawei.com>
Subject: [PATCH v3] malloc: fix memleak in function muntrace
Date: Tue, 21 Apr 2020 19:48:00 +0800	[thread overview]
Message-ID: <20200421114800.26450-1-chenzefeng2@huawei.com> (raw)

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(+)

diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 7e7719df97..5d7bc62857 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -365,4 +365,6 @@ muntrace (void)
 
   fprintf (f, "= End\n");
   fclose (f);
+  free (malloc_trace_buffer);
+  malloc_trace_buffer == NULL;
 }
-- 
2.12.3


             reply	other threads:[~2020-04-21 11:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 11:48 chenzefeng [this message]
2020-04-22 12:39 ` Florian Weimer
2020-04-24  1:24   ` chenzefeng (A)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200421114800.26450-1-chenzefeng2@huawei.com \
    --to=chenzefeng2@huawei.com \
    --cc=dj@redhat.com \
    --cc=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    --cc=liucheng32@huawei.com \
    --cc=zackw@panix.com \
    --cc=zengweilin@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).