fix: avoid cmd double-free in procevent_monitor

There is a possible execution path in procevent_monitor function,
when allocated memory for cmd may be deallocated twice.

Commit adds check before deallocating memory.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
This commit is contained in:
Mikhail Dmitrichenko 2025-07-31 12:20:52 +03:00
parent ab605f26e2
commit 5ec00f70c8

View file

@ -496,7 +496,9 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my
sprintf(lineptr, "\n");
else {
sprintf(lineptr, " %s\n", cmd);
free(cmd);
if (cmd != pids[pid].option.event.cmd) {
free(cmd);
}
}
lineptr += strlen(lineptr);
}