mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
ch_monitor: Avoid possible double free in virCHMonitorClose()
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>
This commit is contained in:
parent
4be361a385
commit
f1f4cbb50a
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user