]> xenbits.xensource.com Git - libvirt.git/commit
qemu_namespace: Don't leak memory in qemuDomainGetPreservedMounts()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 31 Oct 2022 14:38:13 +0000 (15:38 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 1 Nov 2022 13:51:48 +0000 (14:51 +0100)
commitbca7a53333ead7c1afd178728de74c2977cd4b5e
tree8b7555dfca6336ee599f0ce07c53ba0458debb2e
parentecb8c93196a5c58133eb308acd953d3c7f3d08ba
qemu_namespace: Don't leak memory in qemuDomainGetPreservedMounts()

The aim of qemuDomainGetPreservedMounts() is to get a list of
filesystems mounted under /dev and optionally generate a path for
each one where they are moved temporarily when building the
namespace. And the function tries to be a bit clever about it.
For instance, if /dev/shm mount point exists, there's no need to
consider /dev/shm/a nor /dev/shm/b as preserving just 'top level'
/dev/shm gives the same result. To achieve this, the function
iterates over the list of filesystem as returned by
virFileGetMountSubtree() and removes the nested ones. However, it
does so in a bit clumsy way: plain VIR_DELETE_ELEMENT() is used
without freeing the string itself. Therefore, if all three
aforementioned example paths appeared on the list, /dev/shm/a and
/dev/shm/b strings would be leaked.

And when I think about it more, there's no real need to shrink
the array down (realloc()). It's going to be free()-d when
returning from the function. Switch to
VIR_DELETE_ELEMENT_INPLACE() then.

Fixes: cdd9205dfffa3aaed935446a41f0d2dd1357c268
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_namespace.c