]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch_monitor: Avoid possible double free in virCHMonitorClose()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 11 Nov 2024 13:40:32 +0000 (14:40 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Nov 2024 08:11:36 +0000 (09:11 +0100)
The virCHMonitorClose() is meant to be called when monitor to
cloud-hypervisor process closes. It removes the socket and frees
string containing path to the socket.

In general, there is a problem with the following pattern:

  if (var) {
      do_something();
      g_free(var);
  }

because if the pattern executes twice the variable is freed
twice. That's why we have VIR_FREE() macro. Well, replace plain
g_free() with g_clear_pointer(). Mind you, this is NOT a
destructor where clearing pointers is needless.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/ch/ch_monitor.c

index ccd04cfbd19cf1dc4d63baa91cfa68eb877e5019..18ca5a764e0441c21361763ca307c8105a81df8c 100644 (file)
@@ -626,7 +626,7 @@ void virCHMonitorClose(virCHMonitor *mon)
             VIR_WARN("Unable to remove CH socket file '%s'",
                      mon->socketpath);
         }
-        g_free(mon->socketpath);
+        g_clear_pointer(&mon->socketpath, g_free);
     }
 
     virObjectUnref(mon);