* [PATCH 0/2] Small fixes for qga
@ 2023-10-01 18:38 Daniel Xu
2023-10-01 18:38 ` [PATCH 1/2] qga: Fix memory leak when output stream is unused Daniel Xu
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Daniel Xu @ 2023-10-01 18:38 UTC (permalink / raw)
To: qemu-devel, armbru, berrange, kkostiuk
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/cover.1695034158.git.dxu@dxuuu.xyz/
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(-)
--
2.42.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] qga: Fix memory leak when output stream is unused
2023-10-01 18:38 [PATCH 0/2] Small fixes for qga Daniel Xu
@ 2023-10-01 18:38 ` Daniel Xu
2023-10-01 18:38 ` [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated Daniel Xu
2023-10-13 16:43 ` [PATCH 0/2] Small fixes for qga Konstantin Kostiuk
2 siblings, 0 replies; 6+ messages in thread
From: Daniel Xu @ 2023-10-01 18:38 UTC (permalink / raw)
To: michael.roth, kkostiuk, armbru, berrange; +Cc: qemu-devel
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.
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
qga/commands.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/qga/commands.c b/qga/commands.c
index 09c683e263..ce172edd2d 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -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);
--
2.42.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated
2023-10-01 18:38 [PATCH 0/2] Small fixes for qga Daniel Xu
2023-10-01 18:38 ` [PATCH 1/2] qga: Fix memory leak when output stream is unused Daniel Xu
@ 2023-10-01 18:38 ` Daniel Xu
2023-10-01 19:18 ` Konstantin Kostiuk
2023-10-13 13:26 ` Markus Armbruster
2023-10-13 16:43 ` [PATCH 0/2] Small fixes for qga Konstantin Kostiuk
2 siblings, 2 replies; 6+ messages in thread
From: Daniel Xu @ 2023-10-01 18:38 UTC (permalink / raw)
To: michael.roth, kkostiuk, armbru, berrange; +Cc: qemu-devel
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 <dxu@dxuuu.xyz>
---
qga/qapi-schema.json | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index b720dd4379..876e2a8ea8 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated
2023-10-01 18:38 ` [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated Daniel Xu
@ 2023-10-01 19:18 ` Konstantin Kostiuk
2023-10-13 13:26 ` Markus Armbruster
1 sibling, 0 replies; 6+ messages in thread
From: Konstantin Kostiuk @ 2023-10-01 19:18 UTC (permalink / raw)
To: Daniel Xu; +Cc: michael.roth, armbru, berrange, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1517 bytes --]
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
On Sun, Oct 1, 2023 at 9:39 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
> 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 <dxu@dxuuu.xyz>
> ---
> qga/qapi-schema.json | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index b720dd4379..876e2a8ea8 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -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
>
>
[-- Attachment #2: Type: text/html, Size: 2030 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated
2023-10-01 18:38 ` [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated Daniel Xu
2023-10-01 19:18 ` Konstantin Kostiuk
@ 2023-10-13 13:26 ` Markus Armbruster
1 sibling, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2023-10-13 13:26 UTC (permalink / raw)
To: Daniel Xu; +Cc: michael.roth, kkostiuk, berrange, qemu-devel
Daniel Xu <dxu@dxuuu.xyz> writes:
> 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 <dxu@dxuuu.xyz>
> ---
> qga/qapi-schema.json | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index b720dd4379..876e2a8ea8 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -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.
Two spaces between sentences for consistency, please.
With that:
Acked-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Small fixes for qga
2023-10-01 18:38 [PATCH 0/2] Small fixes for qga Daniel Xu
2023-10-01 18:38 ` [PATCH 1/2] qga: Fix memory leak when output stream is unused Daniel Xu
2023-10-01 18:38 ` [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated Daniel Xu
@ 2023-10-13 16:43 ` Konstantin Kostiuk
2 siblings, 0 replies; 6+ messages in thread
From: Konstantin Kostiuk @ 2023-10-13 16:43 UTC (permalink / raw)
To: Daniel Xu; +Cc: qemu-devel, armbru, berrange
[-- Attachment #1: Type: text/plain, Size: 678 bytes --]
merged
On Sun, Oct 1, 2023 at 9:39 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
> 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/cover.1695034158.git.dxu@dxuuu.xyz/
>
> 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(-)
>
> --
> 2.42.0
>
>
[-- Attachment #2: Type: text/html, Size: 1117 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-13 16:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-01 18:38 [PATCH 0/2] Small fixes for qga Daniel Xu
2023-10-01 18:38 ` [PATCH 1/2] qga: Fix memory leak when output stream is unused Daniel Xu
2023-10-01 18:38 ` [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated Daniel Xu
2023-10-01 19:18 ` Konstantin Kostiuk
2023-10-13 13:26 ` Markus Armbruster
2023-10-13 16:43 ` [PATCH 0/2] Small fixes for qga Konstantin Kostiuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).