]> git.ipfire.org Git - thirdparty/qemu.git/commit
qga: Fix memory leak when output stream is unused
authorDaniel Xu <dxu@dxuuu.xyz>
Sun, 1 Oct 2023 18:38:25 +0000 (12:38 -0600)
committerMichael Tokarev <mjt@tls.msk.ru>
Wed, 3 Sep 2025 07:04:25 +0000 (10:04 +0300)
commit978cd0679d0de6a0a0a3e85177f72eb89a35e513
tree4559db612898ef385874f0f4f14599f478ef964c
parentc8f0f7c1f3e4e902b37f4b821354d0a638d65737
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.

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
(cherry picked from commit d6f67b83b81bf49b5c62e77143ed39c020e51830)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
qga/commands.c