mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
node_device: Don't leak error message buffer from virMdevctlListDefined|Active
nodeDeviceUpdateMediatedDevices invokes virMdevctlListDefined and virMdevctlListActive both of which were passed the same 'errmsg' buffer. Since virCommandSetErrorBuffer() always allocates the error buffer one of them was leaked. Fix it by populating the 'errmsg' buffer only on failure of virMdevctlListActive|Defined which invoke the command. Add a comment to nodeDeviceGetMdevctlListCommand reminding how virCommandSetErrorBuffer() works. Fixes: 44a0f2f0c8f Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
This commit is contained in:
parent
294cf405d5
commit
7ca777cc09
@ -1044,6 +1044,15 @@ virMdevctlSetAutostart(virNodeDeviceDef *def, bool autostart, char **errmsg)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nodeDeviceGetMdevctlListCommand:
|
||||
* @defined: list mdevctl entries with persistent config
|
||||
* @output: filled with the output of mdevctl once invoked
|
||||
* @errmsg: always allocated, optionally filled with error from 'mdevctl'
|
||||
*
|
||||
* Prepares a virCommand structure to invoke 'mdevctl' caller is responsible to
|
||||
* free the buffers which are filled by the virCommand infrastructure.
|
||||
*/
|
||||
virCommand*
|
||||
nodeDeviceGetMdevctlListCommand(bool defined,
|
||||
char **output,
|
||||
@ -1624,9 +1633,11 @@ virMdevctlListDefined(virNodeDeviceDef ***devs, char **errmsg)
|
||||
{
|
||||
int status;
|
||||
g_autofree char *output = NULL;
|
||||
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(true, &output, errmsg);
|
||||
g_autofree char *errbuf = NULL;
|
||||
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(true, &output, &errbuf);
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0 || status != 0) {
|
||||
*errmsg = g_steal_pointer(&errbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1642,9 +1653,11 @@ virMdevctlListActive(virNodeDeviceDef ***devs, char **errmsg)
|
||||
{
|
||||
int status;
|
||||
g_autofree char *output = NULL;
|
||||
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(false, &output, errmsg);
|
||||
g_autofree char *errbuf = NULL;
|
||||
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(false, &output, &errbuf);
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0 || status != 0) {
|
||||
*errmsg = g_steal_pointer(&errbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user