Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Feb 2026 23:10:35 +0000
From:      David Bright <dab@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 42ab99095b7d - main - procstat: CID 1593951: Resource leak
Message-ID:  <699f816b.3b3d9.505fb456@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by dab:

URL: https://cgit.FreeBSD.org/src/commit/?id=42ab99095b7dc2243629574e1c627cf5e6a9070c

commit 42ab99095b7dc2243629574e1c627cf5e6a9070c
Author:     David Bright <dab@FreeBSD.org>
AuthorDate: 2026-02-21 22:47:00 +0000
Commit:     David Bright <dab@FreeBSD.org>
CommitDate: 2026-02-22 21:29:25 +0000

    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
---
 usr.bin/procstat/procstat_kqueue.c | 6 ++++--
 1 file 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);
 }
 


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?699f816b.3b3d9.505fb456>