]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_monitor_json: Don't transfer ownership to @msg
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 21 Oct 2021 10:53:35 +0000 (12:53 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Oct 2021 11:42:00 +0000 (13:42 +0200)
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>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c

index 81d90878393077c495426598b78ef5d50a9fc086..908ee0d302ec78786354c34383584571418226d1 100644 (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 */
index f452d0d306e9dad8eaf40387ec28dd98d62ecd73..2508e895033a3e9b3222d85806b211c9737809a3 100644 (file)
@@ -39,7 +39,7 @@ typedef struct _qemuMonitorMessage qemuMonitorMessage;
 struct _qemuMonitorMessage {
     int txFD;
 
-    char *txBuffer;
+    const char *txBuffer;
     int txOffset;
     int txLength;
 
index dcf9186191a05047d8fd7dcca358b87cc982f47c..6d8ccd91e89eee866dc01f924e886e42bd0f7009 100644 (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;
 }