From 49bd9632941f6da43c66591261049837c24a6c6e Mon Sep 17 00:00:00 2001 From: Oliver Webb Date: Tue, 12 Sep 2023 16:36:44 -0500 Subject: [PATCH] Fixed Memory Leak in ts.c and make -i and -s use gmtime --- toys/other/ts.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toys/other/ts.c b/toys/other/ts.c index 5677ca99..f548aaaf 100644 --- a/toys/other/ts.c +++ b/toys/other/ts.c @@ -35,18 +35,18 @@ static long long millinow(void) void ts_main(void) { - char *line, *mm = toybuf+sizeof(toybuf)-8, + char *mm = toybuf+sizeof(toybuf)-8, *format = toys.optflags ? "%T" : "%b %d %T"; long long start = millinow(), now, diff, rel = !!(toys.optflags&~FLAG_m); struct tm *tm; time_t tt; - while ((line = xgetline(stdin))) { + for (char *line; (line = xgetline(stdin)); free(line)) { now = millinow(); diff = now - start*rel; if (FLAG(m)) sprintf(mm, ".%03lld", diff%1000); tt = diff/1000; - tm = localtime(&tt); + tm = (FLAG(i) || FLAG(s)) ? gmtime(&tt) : localtime(&tt); if (FLAG(i)) start = now; strftime(toybuf, sizeof(toybuf)-16, *toys.optargs ? : format, tm); xprintf("%s%s %s\n", toybuf, mm, line); -- 2.39.2