qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] qga: fix a memory leak in qmp_guest_exec_status()
  2021-06-30 17:44 [PATCH v2] qga: fix a memory leak in qmp_guest_exec_status() Yi Wang
@ 2021-06-30 14:02 ` Marc-André Lureau
  0 siblings, 0 replies; 2+ messages in thread
From: Marc-André Lureau @ 2021-06-30 14:02 UTC (permalink / raw)
  To: Yi Wang; +Cc: wang.liang82, Wang Yechao, QEMU, xue.zhihong

[-- Attachment #1: Type: text/plain, Size: 1742 bytes --]

On Wed, Jun 30, 2021 at 1:55 PM Yi Wang <wang.yi59@zte.com.cn> wrote:

> From: Wang Yechao <wang.yechao255@zte.com.cn>
>
> In some case, $GuestExecInfo.out.length maybe zero and the memory
> is leaked in qmp_guest_exec_status(). Call g_free() on the fileds
> directly to fix memory leak (NULL is ignored).
>
> $GuestExecInfo.err.data has the same problem.
>
> Signed-off-by: Yechao Wang <wang.yechao255@zte.com.cn>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
> Changes in v2:
>  - do not check the size > 0 when call g_free. Thanks to Marc.
> ---
>  qga/commands.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/qga/commands.c b/qga/commands.c
> index d3fec80..26e9358 100644
> --- a/qga/commands.c
> +++ b/qga/commands.c
>
> @@ -214,17 +214,18 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp)
>          if (gei->out.length > 0) {
>              ges->has_out_data = true;
>
>              ges->out_data = g_base64_encode(gei->out.data, gei->out.length);
> -            g_free(gei->out.data);
>              ges->has_out_truncated = gei->out.truncated;
>          }
>
>          if (gei->err.length > 0) {
>              ges->has_err_data = true;
>
>              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->out.data);
> +        g_free(gei->err.data);
> +
>          QTAILQ_REMOVE(&guest_exec_state.processes, gei, next);
>          g_free(gei);
>      }
> --
> 1.8.3.1
>


-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2906 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2] qga: fix a memory leak in qmp_guest_exec_status()
@ 2021-06-30 17:44 Yi Wang
  2021-06-30 14:02 ` Marc-André Lureau
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Wang @ 2021-06-30 17:44 UTC (permalink / raw)
  To: qemu-devel, marcandre.lureau
  Cc: wang.yi59, Wang Yechao, wang.liang82, xue.zhihong


[-- Attachment #1.1.1: Type: text/plain, Size: 1477 bytes --]

From: Wang Yechao <wang.yechao255@zte.com.cn>

In some case, $GuestExecInfo.out.length maybe zero and the memory
is leaked in qmp_guest_exec_status(). Call g_free() on the fileds
directly to fix memory leak (NULL is ignored).

$GuestExecInfo.err.data has the same problem.

Signed-off-by: Yechao Wang <wang.yechao255@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>

---
Changes in v2:
 - do not check the size > 0 when call g_free. Thanks to Marc.
---
 qga/commands.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/qga/commands.c b/qga/commands.c
index d3fec80..26e9358 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -214,17 +214,18 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp)
         if (gei->out.length > 0) {
             ges->has_out_data = true;
             ges->out_data = g_base64_encode(gei->out.data, gei->out.length);
-            g_free(gei->out.data);
             ges->has_out_truncated = gei->out.truncated;
         }
 
         if (gei->err.length > 0) {
             ges->has_err_data = true;
             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->out.data);
+        g_free(gei->err.data);
+
         QTAILQ_REMOVE(&guest_exec_state.processes, gei, next);
         g_free(gei);
     }
-- 
1.8.3.1

[-- Attachment #1.1.2: Type: text/html , Size: 3165 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-30 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 17:44 [PATCH v2] qga: fix a memory leak in qmp_guest_exec_status() Yi Wang
2021-06-30 14:02 ` Marc-André Lureau

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).