]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: fix potential leak of command
authorJonathon Jongsma <jjongsma@redhat.com>
Tue, 20 Apr 2021 13:57:10 +0000 (08:57 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Mon, 26 Apr 2021 17:24:22 +0000 (12:24 -0500)
When returning early due to errors, cmd will be leaked. Use an autoptr
to handle these early returns without leaking memory.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/node_device/node_device_driver.c

index b0cc63ed42223414de488765bda52922e3cfe90c..e565cc29ecb4de495e2ab380f8661586c15e9569 100644 (file)
@@ -724,7 +724,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
                             char **errbuf)
 {
     g_autofree char *parent_addr = NULL;
-    virCommand *cmd = NULL;
+    g_autoptr(virCommand) cmd = NULL;
     const char *subcommand = virMdevctlCommandTypeToString(cmd_type);
     g_autofree char *inbuf = NULL;
 
@@ -787,7 +787,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
 
     virCommandSetErrorBuffer(cmd, errbuf);
 
-    return cmd;
+    return g_steal_pointer(&cmd);
 }