@samitouri / QOSamiQemu / commits / 59f9e694af

system/vl: Free allocate memory for pid file name in case realpath() failed

In case realpath() fails, the code returns early in the function qemu_maybe_daemonize(), without freeing the allocated memory. Add a g_free() here to fix it. And while we're at it, also free the memory in the qemu_unlink_pidfile() function - it's not that important since QEMU is going to terminate anyway, but some malloc sanitizers might still complain if we don't free it. Fixes: dee2a4d4d2f ("vl: defuse PID file path resolve error") Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Fiona Ebner <f.ebner@proxmox.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260518114514.684401-1-thuth@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thomas Huth committed May 18, 2026 at 13:45 UTC 59f9e694afd96bd63c05c1e8351d07fddbabe8c0
1 file changed +3
system/vl.c
+3
@@ -1634,6 +1634,8 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
1634
1635 upn = DO_UPCAST(struct UnlinkPidfileNotifier, notifier, n);
1636 unlink(upn->pid_file_realpath);
1637 + g_free(upn->pid_file_realpath);
1638 + upn->pid_file_realpath = NULL;
1639 }
1640
1641 static const QEMUOption *lookup_opt(int argc, char **argv,
@@ -2672,6 +2674,7 @@ static void qemu_maybe_daemonize(const char *pid_file)
2674 warn_report("not removing PID file on exit: cannot resolve PID "
2675 "file path: %s: %s", pid_file, strerror(errno));
2676 }
2677 + g_free(pid_file_realpath);
2678 return;
2679 }
2680