From: Denis Kirjanov Date: Wed, 28 Feb 2024 13:58:57 +0000 (-0500) Subject: nstat: use stack space for history file name X-Git-Tag: v6.9.0~32^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2f8b36e146a555fd6a96590bf191ac634e3b350b;p=thirdparty%2Fiproute2.git nstat: use stack space for history file name as the name doesn't require a lot of storage put it on the stack. Moreover the memory allocated via malloc wasn't returned. Signed-off-by: Denis Kirjanov Signed-off-by: David Ahern --- diff --git a/misc/nstat.c b/misc/nstat.c index 3a58885d..ea96ccb0 100644 --- a/misc/nstat.c +++ b/misc/nstat.c @@ -580,7 +580,7 @@ static const struct option longopts[] = { int main(int argc, char *argv[]) { - char *hist_name; + char hist_name[128]; struct sockaddr_un sun; FILE *hist_fp = NULL; int ch; @@ -668,10 +668,11 @@ int main(int argc, char *argv[]) patterns = argv; npatterns = argc; - if ((hist_name = getenv("NSTAT_HISTORY")) == NULL) { - hist_name = malloc(128); - sprintf(hist_name, "/tmp/.nstat.u%d", getuid()); - } + if (getenv("NSTAT_HISTORY")) + snprintf(hist_name, sizeof(hist_name), + "%s", getenv("NSTAT_HISTORY")); + else + snprintf(hist_name, sizeof(hist_name), "/tmp/.nstat.u%d", getuid()); if (reset_history) unlink(hist_name);