From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4842 invoked from network); 9 May 2023 12:57:58 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 9 May 2023 12:57:58 -0000 Received: (qmail 24027 invoked by uid 550); 9 May 2023 12:57:55 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 23983 invoked from network); 9 May 2023 12:57:54 -0000 From: Xiaoming Ni To: , CC: , Date: Tue, 9 May 2023 20:44:24 +0800 Message-ID: <20230509124424.56508-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected Subject: [musl] [PATCH] time/tz: Fix memory leak when do_tzset() is repeated When do_tzset() and setenv("TZ") are repeatedly called, "old_tz" is repeatedly applied for memory and is not released, triggering memory leakage. s = getenv("TZ"); i = strlen(s); if (i >= old_tz_size) { old_tz = malloc(old_tz_size);// without free old value } add free(old_tz) to avoid memory leak. Signed-off-by: Xiaoming Ni --- src/time/__tz.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/time/__tz.c b/src/time/__tz.c index c34b3eb7..917740ea 100644 --- a/src/time/__tz.c +++ b/src/time/__tz.c @@ -151,6 +151,7 @@ static void do_tzset() old_tz_size *= 2; if (i >= old_tz_size) old_tz_size = i+1; if (old_tz_size > PATH_MAX+2) old_tz_size = PATH_MAX+2; + if (old_tz != old_tz_buf) free(old_tz); old_tz = malloc(old_tz_size); } if (old_tz) memcpy(old_tz, s, i+1); -- 2.27.0