This patch fixes a memory leak in ts by making sure it frees the pointers given
by xgetline()
I knew about this leak for a few days and was planning to submit a patch for it
some time in the future,
but now that ts got promoted I feel like I should submit it sooner rather then
later
The other fix is that if it's doing -i or -s it uses gmtime() instead of
localtime()
so the timestamp starts at 00:00:00 instead of something like 20:00:00 for PDT
or 18:00:00 for CST.
From 2876beb6ddec1f6caccbfe783faaaebeef712751 Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobby...@proton.me>
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.34.1
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net