qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PULL 15/18] accel: kvm: Fix memory leak in find_stats_descriptors


From: Peter Maydell
Subject: Re: [PULL 15/18] accel: kvm: Fix memory leak in find_stats_descriptors
Date: Tue, 19 Jul 2022 14:29:23 +0100

On Tue, 12 Jul 2022 at 13:57, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> From: Miaoqian Lin <linmq006@gmail.com>
>
> This function doesn't release descriptors in one error path,
> result in memory leak. Call g_free() to release it.
>
> Fixes: cc01a3f4cadd ("kvm: Support for querying fd-based stats")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> Message-Id: <20220624063159.57411-1-linmq006@gmail.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  accel/kvm/kvm-all.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index ba3210b1c1..ed8b6b896e 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -3891,6 +3891,7 @@ static StatsDescriptors 
> *find_stats_descriptors(StatsTarget target, int stats_fd
>          error_setg(errp, "KVM stats: failed to read stats header: "
>                     "expected %zu actual %zu",
>                     sizeof(*kvm_stats_header), ret);
> +        g_free(descriptors);
>          return NULL;
>      }
>      size_desc = sizeof(*kvm_stats_desc) + kvm_stats_header->name_size;

Hi; this has fixed one memory leak in this error-exit path but
missed the other: it should also
   g_free(kvm_stats_header);

Spotted by Coverity, CID 1490142.

This g_free() is also missing from the other error-exit codepath
in the function (the "failed to read stats descriptors" one).

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]