[libvirt PATCH v2 1/3] nodedev: fix potential leak of command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Reviewed-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/node_device/node_device_driver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index b0cc63ed42..e565cc29ec 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -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);
 }
 
 
-- 
2.26.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux