On 10/17/19 9:10 AM, Michal Privoznik wrote:
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(a)redhat.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb413(a)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.
Interesting. I'll keep an eye for this kind of usage next time.
Thanks,
DHB
> ret = qemuDomainSaveMemory(driver, vm, path, data,
> compressedpath,
> flags, QEMU_ASYNC_JOB_SAVE);
Michal