|
Message-ID: <20230509124424.56508-1-nixiaoming@huawei.com> Date: Tue, 9 May 2023 20:44:24 +0800 From: Xiaoming Ni <nixiaoming@...wei.com> To: <dalias@...ifal.cx>, <musl@...ts.openwall.com> CC: <nixiaoming@...wei.com>, <liucheng32@...wei.com> Subject: [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 <nixiaoming@...wei.com> --- 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.