Small fixes for qga
cover Small fixes for qga
These are two small fixes that fell out of [0]. Since we are not moving forward with that patchset, I thought it would be good to at least send the fixes that came out of it.
See commits for more details.
[0]: https://lore.kernel.org/qemu-devel/[email protected]/
Daniel Xu (2):
qga: Fix memory leak when output stream is unused
qapi: qga: Clarify when out-data and err-data are populated
qga/commands.c | 4 ++-- qga/qapi-schema.json | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/2 qga: Fix memory leak when output stream is unused
If capture-output is requested but one of the channels goes unused (eg. we attempt to capture stderr but the command never writes to stderr), we can leak memory.
guest_exec_output_watch() is (from what I understand) unconditionally called for both streams if output capture is requested. The first call will always pass the p->size == p->length check b/c both values are
0. Then GUEST_EXEC_IO_SIZE bytes will be allocated for the stream.
But when we reap the exited process there's a gei->err.length > 0 check to actually free the buffer. Which does not get run if the command doesn't write to the stream.
Fix by making free() unconditional.
--- qga/commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qga/commands.c +2 -2
@@ -206,15 +206,15 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp)#endif if (gei->out.length >0 ) { ges->out_data =g_base64_encode (gei->out.data, gei->out.length); -g_free (gei->out.data); ges->has_out_truncated = gei->out.truncated; } +g_free (gei->out.data);if (gei->err.length >0 ) { ges->err_data =g_base64_encode (gei->err.data, gei->err.length); -g_free (gei->err.data); ges->has_err_truncated = gei->err.truncated; } +g_free (gei->err.data);QTAILQ_REMOVE (&guest_exec_state.processes, gei, next);g_free (gei);
Signature · 1 line
2.42.0
PATCH 2/2 qapi: qga: Clarify when out-data and err-data are populated
In reply to Daniel XuIf output is being captured for a guest-exec invocation, the out-data and err-data fields of guest-exec-status are only populated after the process is reaped. This is somewhat counter intuitive and too late to change. Thus, it would be good to document the behavior.
--- qga/qapi-schema.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
qga/qapi-schema.json +5 -3
@@ -1220,11 +1220,13 @@ # @signal: signal number (linux) or unhandled exception code (windows) # if the process was abnormally terminated. # -# @out-data: base64-encoded stdout of the process +# @out-data: base64-encoded stdout of the process. This field will only +# be populated after the process exits. # -# @err-data: base64-encoded stderr of the process Note: @out-data and +# @err-data: base64-encoded stderr of the process. Note: @out-data and # @err-data are present only if 'capture-output' was specified for -# 'guest-exec' +# 'guest-exec'. This field will only be populated after the process +# exits. # # @out-truncated: true if stdout was not fully captured due to size # limitation.
Signature · 1 line
2.42.0
Re: [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated
Quoted 35 lines · Daniel Xu
If output is being captured for a guest-exec invocation, the out-data and err-data fields of guest-exec-status are only populated after the process is reaped. This is somewhat counter intuitive and too late to change. Thus, it would be good to document the behavior.
Signed-off-by Daniel Xu <[email protected]>--- qga/qapi-schema.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)qga/qapi-schema.json +5
-4@@ -1220,11 +1220,13 @@ # @signal: signal number (linux) or unhandled exception code (windows) # if the process was abnormally terminated. # -# @out-data: base64-encoded stdout of the process +# @out-data: base64-encoded stdout of the process. This field will only +# be populated after the process exits. # -# @err-data: base64-encoded stderr of the process Note: @out-data and +# @err-data: base64-encoded stderr of the process. Note: @out-data and # @err-data are present only if 'capture-output' was specified for -# 'guest-exec' +# 'guest-exec'. This field will only be populated after the process +# exits. # # @out-truncated: true if stdout was not fully captured due to size # limitation. --2.42.0
Re: [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated
In reply to Daniel XuQuoted 21 lines · Daniel Xu
If output is being captured for a guest-exec invocation, the out-data and err-data fields of guest-exec-status are only populated after the process is reaped. This is somewhat counter intuitive and too late to change. Thus, it would be good to document the behavior.
Signed-off-by Daniel Xu <[email protected]>--- qga/qapi-schema.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)qga/qapi-schema.json +2
-1@@ -1220,11 +1220,13 @@ # @signal: signal number (linux) or unhandled exception code (windows) # if the process was abnormally terminated. # -# @out-data: base64-encoded stdout of the process +# @out-data: base64-encoded stdout of the process. This field will only +# be populated after the process exits.
qga/qapi-schema.json line 1232
Quoted 10 lines
qga/qapi-schema.json +3
-2# -# @err-data: base64-encoded stderr of the process Note: @out-data and +# @err-data: base64-encoded stderr of the process. Note: @out-data and # @err-data are present only if 'capture-output' was specified for -# 'guest-exec' +# 'guest-exec'. This field will only be populated after the process +# exits. # # @out-truncated: true if stdout was not fully captured due to size # limitation.
Two spaces between sentences for consistency, please.
With that:
merged
Quoted 21 lines · Daniel Xu
These are two small fixes that fell out of [0]. Since we are not moving forward with that patchset, I thought it would be good to at least send the fixes that came out of it.
See commits for more details.
[0]:
https://lore.kernel.org/qemu-devel/[email protected]/Daniel Xu (2):
qga: Fix memory leak when output stream is unused
qapi: qga: Clarify when out-data and err-data are populatedqga/commands.c | 4 ++-- qga/qapi-schema.json | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-)--
2.42.0