mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu_monitor_json: Don't transfer ownership to @msg
In qemuMonitorJSONCommandWithFd() given command (represented by virJSONValue struct) is translated to string (represented by virBuffer). The ownership of the string is then transferred to the message which is then sent. The downside of this approach is we have to have an explicit call to free the string from the message. But if the message just "borrowed" the string (which it can safely do because it is just reading from the string) then automatic free of the buffer takes care of freeing the string. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
parent
139338ab33
commit
2d7257d528
@ -420,7 +420,7 @@ static int
|
||||
qemuMonitorIOWrite(qemuMonitor *mon)
|
||||
{
|
||||
int done;
|
||||
char *buf;
|
||||
const char *buf;
|
||||
size_t len;
|
||||
|
||||
/* If no active message, or fully transmitted, the no-op */
|
||||
|
@ -39,7 +39,7 @@ typedef struct _qemuMonitorMessage qemuMonitorMessage;
|
||||
struct _qemuMonitorMessage {
|
||||
int txFD;
|
||||
|
||||
char *txBuffer;
|
||||
const char *txBuffer;
|
||||
int txOffset;
|
||||
int txLength;
|
||||
|
||||
|
@ -322,7 +322,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon,
|
||||
virBufferAddLit(&cmdbuf, "\r\n");
|
||||
|
||||
msg.txLength = virBufferUse(&cmdbuf);
|
||||
msg.txBuffer = virBufferContentAndReset(&cmdbuf);
|
||||
msg.txBuffer = virBufferCurrentContent(&cmdbuf);
|
||||
msg.txFD = scm_fd;
|
||||
|
||||
ret = qemuMonitorSend(mon, &msg);
|
||||
@ -338,8 +338,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(msg.txBuffer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user