From patchwork Fri Apr 24 01:24:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenzefeng X-Patchwork-Id: 38863 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by sourceware.org (Postfix) with ESMTPS id 18BAC38930C2 for ; Fri, 24 Apr 2020 01:24:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 18BAC38930C2 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=chenzefeng2@huawei.com Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 704E53A8B7FD5DD0E276; Fri, 24 Apr 2020 09:24:18 +0800 (CST) Received: from linux_supse12sp4_workstation.huawei.com (10.67.189.177) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Fri, 24 Apr 2020 09:24:10 +0800 From: chenzefeng To: , , , CC: , , Subject: [PATCH v4] malloc: fix memleak in function muntrace Date: Fri, 24 Apr 2020 09:24:10 +0800 Message-ID: <20200424012410.74089-1-chenzefeng2@huawei.com> X-Mailer: git-send-email 2.12.3 MIME-Version: 1.0 X-Originating-IP: [10.67.189.177] X-CFilter-Loop: Reflected X-Spam-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Apr 2020 01:24:38 -0000 when we call functons as follow: setenv("MALLOC_TRACE", "/tmp/mtrace.log", 0); mtrace(); ... muntrace(); It would cause memleak, for the mtrace malloc some memory: mtd = malloc(TRACE_BUFFER_SIZE); and it would not be free. Therefore it should be freed in muntrace. Signed-off-by: chenzefeng --- malloc/mtrace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/malloc/mtrace.c b/malloc/mtrace.c index 7e7719df97..61f4ca3520 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; }