mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
nodedevmdevctltest: Fix two memleaks
There are two memleaks inside of nodedevmdevctltest:
1) In the testCommandDryRunCallback() - when appending lines to
stdinbuf the pointer is overwritten without freeing the old
memory it pointed to.
2) In testMdevctlModify() the livecmd variable is reused and
since its marked as g_autoptr() the first use leaks.
Fixes: 582f27ff15
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
3ab5f63f6e
commit
b3a67644c3
@ -33,11 +33,13 @@ testCommandDryRunCallback(const char *const*args G_GNUC_UNUSED,
|
|||||||
{
|
{
|
||||||
char **stdinbuf = opaque;
|
char **stdinbuf = opaque;
|
||||||
|
|
||||||
if (*stdinbuf)
|
if (*stdinbuf) {
|
||||||
*stdinbuf = g_strconcat(*stdinbuf, "\n", input, NULL);
|
g_autofree char *oldbuf = g_steal_pointer(stdinbuf);
|
||||||
else
|
*stdinbuf = g_strconcat(oldbuf, "\n", input, NULL);
|
||||||
|
} else {
|
||||||
*stdinbuf = g_strdup(input);
|
*stdinbuf = g_strdup(input);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef virCommand * (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **);
|
typedef virCommand * (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **);
|
||||||
|
|
||||||
@ -188,6 +190,7 @@ testMdevctlModify(const void *data G_GNUC_UNUSED)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
g_autoptr(virCommand) definedcmd = NULL;
|
g_autoptr(virCommand) definedcmd = NULL;
|
||||||
g_autoptr(virCommand) livecmd = NULL;
|
g_autoptr(virCommand) livecmd = NULL;
|
||||||
|
g_autoptr(virCommand) livecmd_update = NULL;
|
||||||
g_autoptr(virCommand) bothcmd = NULL;
|
g_autoptr(virCommand) bothcmd = NULL;
|
||||||
g_autofree char *errmsg = NULL;
|
g_autofree char *errmsg = NULL;
|
||||||
g_autofree char *stdinbuf = NULL;
|
g_autofree char *stdinbuf = NULL;
|
||||||
@ -222,10 +225,10 @@ testMdevctlModify(const void *data G_GNUC_UNUSED)
|
|||||||
&parser_callbacks, NULL, false)))
|
&parser_callbacks, NULL, false)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(livecmd = nodeDeviceGetMdevctlModifyCommand(def_update, false, true, &errmsg)))
|
if (!(livecmd_update = nodeDeviceGetMdevctlModifyCommand(def_update, false, true, &errmsg)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virCommandRun(livecmd, NULL) < 0)
|
if (virCommandRun(livecmd_update, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(livecmd = nodeDeviceGetMdevctlModifyCommand(def, false, true, &errmsg)))
|
if (!(livecmd = nodeDeviceGetMdevctlModifyCommand(def, false, true, &errmsg)))
|
||||||
|
Loading…
Reference in New Issue
Block a user