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 <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-04-20 08:57:10 -05:00
parent 2384b6cade
commit d0913302a8

View File

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