Merge pull request #6872 from kmk3/procevent-fix-cmd-memleak

bugfix: firemon: fix potential memory leak in procevent_monitor
This commit is contained in:
netblue30 2025-08-20 06:57:00 -04:00 committed by GitHub
commit 6b1b7794a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -471,8 +471,10 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my
int sandbox_closed = 0; // exit sandbox flag
int cmd_dup = 0;
char *cmd = pids[pid].option.event.cmd;
if (!cmd) {
cmd_dup = 1;
cmd = pid_proc_cmdline(pid);
}
if (add_new) {
@ -490,20 +492,22 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my
}
else {
if (!cmd) {
cmd_dup = 1;
cmd = pid_proc_cmdline(pid);
}
if (cmd == NULL || nodisplay)
if (!cmd || nodisplay)
sprintf(lineptr, "\n");
else {
else
sprintf(lineptr, " %s\n", cmd);
if (cmd != pids[pid].option.event.cmd) {
free(cmd);
}
}
lineptr += strlen(lineptr);
}
(void) lineptr;
if (cmd && cmd_dup) {
free(cmd);
cmd = NULL;
}
// print the event
printf("%s", line);
fflush(0);