procstat: CID 1593951: Resource leak

Summary: A trivial resource leak fix; free the allocated memory before return.

Test Plan: Code inspection, run command.

I built a simple program that waits for a signal on a kqueue, then ran
that. The standard procstat displays:

```
fbsd-dev% Waiting for SIGTERM...
procstat -a kqueue
    PID       KQFD   FILTER      IDENT      FLAGS     FFLAGS       DATA      UDATA     STATUS
  84352          3   SIGNAL         15          C          -          0        0x0          -
```

The revised procstat displays:
```
fbsd-dev% sudo LD_LIBRARY_PATH=/usr/obj/usr/home/dab/git/freebsd/src/arm64.aarch64/lib/libutil /usr/obj/usr/home/dab/git/freebsd/src/arm64.aarch64/usr.bin/procstat/procstat -a kqueue
    PID       KQFD   FILTER      IDENT      FLAGS     FFLAGS       DATA      UDATA     STATUS
  84352          3   SIGNAL         15          C          -          0        0x0          -
fbsd-dev%
```

As expected, the two displays are identical. This doesn't prove that
the leak is gone, but it does prove that the revised command still
operates correctly. I think it can clearly be seen from inspection of
the change that the leak has been remedied.

Reviewed-bys: vangyzen
Differential Revision: https://reviews.freebsd.org/D55422
This commit is contained in:
David Bright
2026-02-21 16:47:00 -06:00
parent 8ae3f44991
commit 42ab99095b
+4 -2
View File
@@ -135,8 +135,10 @@ procstat_kqueue_flags(const struct pk_elem *names, unsigned flags, bool commas)
}
}
if (strlen(res) == 0)
return (strdup("-"));
if (strlen(res) == 0) {
free(res);
res = strdup("-");
}
return (res);
}