diff options
| author | David Bright <dab@FreeBSD.org> | 2026-02-21 22:47:00 +0000 |
|---|---|---|
| committer | David Bright <dab@FreeBSD.org> | 2026-02-22 21:29:25 +0000 |
| commit | 42ab99095b7dc2243629574e1c627cf5e6a9070c (patch) | |
| tree | aba9dc2b3a2b131ce4f7bc2ca683586a2bb22ec9 | |
| parent | 8ae3f44991948cc97b09adc248a9a46db71bf9e0 (diff) | |
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
| -rw-r--r-- | usr.bin/procstat/procstat_kqueue.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.bin/procstat/procstat_kqueue.c b/usr.bin/procstat/procstat_kqueue.c index ce9d2cb42fe2..b4d396e12d3a 100644 --- a/usr.bin/procstat/procstat_kqueue.c +++ b/usr.bin/procstat/procstat_kqueue.c @@ -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); } |
