aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kirjanov <kirjanov@gmail.com>2024-02-28 08:58:57 -0500
committerDavid Ahern <dsahern@kernel.org>2024-03-03 22:32:46 +0000
commit2f8b36e146a555fd6a96590bf191ac634e3b350b (patch)
tree063972a89637d4a58ec3d72246e34ba05315c1d4
parent4ce906c3d515973ec3f7c714495d6e3bd15645af (diff)
downloadiproute2-2f8b36e146a555fd6a96590bf191ac634e3b350b.tar.gz
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 <dkirjanov@suse.de> Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r--misc/nstat.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/misc/nstat.c b/misc/nstat.c
index 3a58885d9..ea96ccb03 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);