[libvirt] [PATCH v4 3/5] qemu_driver: use g_autofree when possible
Michal Privoznik
mprivozn at redhat.com
Thu Oct 17 12:10:13 UTC 2019
On 10/16/19 10:54 PM, Daniel Henrique Barboza wrote:
> String and other scalar pointers an be auto-unref, sparing us
> a VIR_FREE() call.
>
> This patch uses g_autofree whenever possible with strings and
> other scalar pointer types.
>
> Suggested-by: Erik Skultety <eskultet at redhat.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
> ---
> src/qemu/qemu_driver.c | 203 ++++++++++++++---------------------------
> 1 file changed, 68 insertions(+), 135 deletions(-)
>
> @@ -3300,7 +3295,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
> int compressed, const char *compressedpath,
> const char *xmlin, unsigned int flags)
> {
> - char *xml = NULL;
> + g_autofree char *xml = NULL;
> bool was_running = false;
> int ret = -1;
> virObjectEventPtr event = NULL;
> @@ -3381,7 +3376,6 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
> if (!(data = virQEMUSaveDataNew(xml, cookie, was_running, compressed,
> driver->xmlopt)))
> goto endjob;
> - xml = NULL;
No, this line has to be here. The point is that virQEMUSaveDataNew()
takes ownership of @xml (in a very clumsy way though), so
qemuDomainSaveInternal() has to refrain from freeing it. Setting it to
NULL is how we achieve that.
>
> ret = qemuDomainSaveMemory(driver, vm, path, data, compressedpath,
> flags, QEMU_ASYNC_JOB_SAVE);
Michal
More information about the libvir-list
mailing list