From: Jonathon Jongsma Date: Tue, 20 Apr 2021 13:57:10 +0000 (-0500) Subject: nodedev: fix potential leak of command X-Git-Tag: v7.3.0-rc1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0913302a8590fce22b542eaea8966d5fefba47b;p=thirdparty%2Flibvirt.git nodedev: fix potential leak of command 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 Reviewed-by: Michal Privoznik --- 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); }