From: Wang Yechao <wang.yechao...@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.yechao...@zte.com.cn> Signed-off-by: Yi Wang <wang.y...@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