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:
Michal Privoznik 2021-10-21 12:53:35 +02:00
parent 139338ab33
commit 2d7257d528
3 changed files with 3 additions and 5 deletions

View File

@ -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 */

View File

@ -39,7 +39,7 @@ typedef struct _qemuMonitorMessage qemuMonitorMessage;
struct _qemuMonitorMessage {
int txFD;
char *txBuffer;
const char *txBuffer;
int txOffset;
int txLength;

View File

@ -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;
}