public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: chenzefeng <chenzefeng2@huawei.com>
To: <libc-alpha@sourceware.org>
Cc: <liucheng32@huawei.com>, <chenzefeng2@huawei.com>,
	<zengweilin@huawei.com>
Subject: [PATCH] malloc: fix memleak in function muntrace
Date: Sun, 19 Apr 2020 15:37:54 +0800	[thread overview]
Message-ID: <20200419073754.72967-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..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);
 }
-- 
2.12.3


             reply	other threads:[~2020-04-19  7:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-19  7:37 chenzefeng [this message]
2020-04-19 11:39 ` Florian Weimer
2020-04-20 13:49   ` 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=20200419073754.72967-1-chenzefeng2@huawei.com \
    --to=chenzefeng2@huawei.com \
    --cc=libc-alpha@sourceware.org \
    --cc=liucheng32@huawei.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).