Skip to contentSkip to conversation

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

PATCH Superseded Thomas Huth 3 participants 5 messages May 15 – May 18

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

From: Thomas Huth <[email protected]>

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.

Fixes dee2a4d4d2f ("vl: defuse PID file path resolve error")
---
 system/vl.c | 1 +
 1 file changed, 1 insertion(+)
system/vl.c +1 -0
index d2f4044e5d8..7e2ed898240 100644
@@ -2670,6 +2670,7 @@ static void qemu_maybe_daemonize(const char *pid_file)
                 warn_report("not removing PID file on exit: cannot resolve PID "
                             "file path: %s: %s", pid_file, strerror(errno));
             }
+            g_free(pid_file_realpath);
             return;
         }
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 17 lines · Thomas Huth

From: Thomas Huth <[email protected]>

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.

Fixes dee2a4d4d2f ("vl: defuse PID file path resolve error")
---
  system/vl.c | 1 +
  1 file changed, 1 insertion(+)
system/vl.c +0 -0
index d2f4044e5d8..7e2ed898240 100644

system/vl.c static void qemu_maybe_daemonize(const char *pid_file) · line 2676

Quoted 7 lines
system/vl.c +1 -0
@@ -2670,6 +2670,7 @@ static void qemu_maybe_daemonize(const char *pid_file)
                  warn_report("not removing PID file on exit: cannot resolve PID "
                              "file path: %s: %s", pid_file, strerror(errno));
              }
+            g_free(pid_file_realpath);
              return;
          }
 

Don't we also need to release the other paths?

- qemu_unlink_pidfile()
- pid_file_init()
- pid_file_cleanup()

#2 lore raw
Quoted 27 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Thomas Huth

From: Thomas Huth <[email protected]>

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.

Fixes dee2a4d4d2f ("vl: defuse PID file path resolve error")

---
  system/vl.c | 1 +

  1 file changed, 1 insertion(+)
system/vl.c +0 -0
index d2f4044e5d8..7e2ed898240 100644
@@ -2670,6 +2670,7 @@ static void qemu_maybe_daemonize(const char *pid_file)
Quoted 6 lines

                  warn_report("not removing PID file on exit: cannot resolve PID " "file path: %s: %s", pid_file, strerror(errno)); }
+            g_free(pid_file_realpath);
              return;
          }

Don't we also need to release the other paths?

Quoted 3 lines

 - qemu_unlink_pidfile()
 - pid_file_init()
 - pid_file_cleanup()

Adding it to qemu_unlink_pidfile() makes sense here (though QEMU is terminating anyway afterwards, some malloc sanitizers might complain otherwise), so I sent a v2 for this.

pid_file_init() and pid_file_cleanup() is in the storage daemon, so this is a separate problem (the variable just has the same name there). Not sure whether it's worth the effort to free the memory there, too, since the code exits afterwards anyway, and the pointer is kept 'til the end?

Thomas

#3 lore raw
Quoted 29 lines · Thomas Huth
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Thomas Huth

From: Thomas Huth <[email protected]>

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.

Fixes dee2a4d4d2f ("vl: defuse PID file path resolve error")

---
  system/vl.c | 1 +

  1 file changed, 1 insertion(+)
system/vl.c +0 -0
index d2f4044e5d8..7e2ed898240 100644
@@ -2670,6 +2670,7 @@ static void qemu_maybe_daemonize(const char 
 *pid_file)
Quoted 6 lines

                  warn_report("not removing PID file on exit: cannot resolve PID " "file path: %s: %s", pid_file, strerror(errno)); }
+            g_free(pid_file_realpath);
              return;
          }

Don't we also need to release the other paths?

Quoted 7 lines
Quoted 3 lines

  - qemu_unlink_pidfile()
  - pid_file_init()
  - pid_file_cleanup()

Adding it to qemu_unlink_pidfile() makes sense here (though QEMU is terminating anyway afterwards, some malloc sanitizers might complain otherwise), so I sent a v2 for this.

pid_file_init() and pid_file_cleanup() is in the storage daemon, so this is a separate problem (the variable just has the same name there). Not sure whether it's worth the effort to free the memory there, too, since the code exits afterwards anyway, and the pointer is kept 'til the end?

OK, fine!

Quoted 4 lines

 Thomas

Reviewed-by on v1 1/1
#4 lore raw
In reply to Thomas Huth

Am 15.05.26 um 4:39 PM schrieb Thomas Huth:

Quoted 8 lines

From: Thomas Huth <[email protected]>

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.

Fixes dee2a4d4d2f ("vl: defuse PID file path resolve error")

Thanks!

Quoted 16 lines
---
 system/vl.c | 1 +
 1 file changed, 1 insertion(+)
system/vl.c +1 -0
index d2f4044e5d8..7e2ed898240 100644
@@ -2670,6 +2670,7 @@ static void qemu_maybe_daemonize(const char *pid_file)
                 warn_report("not removing PID file on exit: cannot resolve PID "
                             "file path: %s: %s", pid_file, strerror(errno));
             }
+            g_free(pid_file_realpath);
             return;
         }