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@xxxxxxxxxx> --- src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 81d9087839..908ee0d302 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -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 */ diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index f452d0d306..2508e89503 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -39,7 +39,7 @@ typedef struct _qemuMonitorMessage qemuMonitorMessage; struct _qemuMonitorMessage { int txFD; - char *txBuffer; + const char *txBuffer; int txOffset; int txLength; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index dcf9186191..6d8ccd91e8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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; } -- 2.32.0