qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm: fix memory leak on failure to read stats descriptors
@ 2022-09-05 10:06 Paolo Bonzini
  2022-09-05 10:56 ` Richard Henderson
  2022-09-05 10:59 ` Marc-André Lureau
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-09-05 10:06 UTC (permalink / raw)
  To: qemu-devel

Reported by Coverity as CID 1490142.

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 7c8ce18bdd..208b0c74e3 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -3962,6 +3962,7 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
                    size_desc * kvm_stats_header->num_desc, ret);
         g_free(descriptors);
         g_free(kvm_stats_desc);
+        g_free(kvm_stats_header);
         return NULL;
     }
     descriptors->kvm_stats_header = kvm_stats_header;
-- 
2.37.2



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

* Re: [PATCH] kvm: fix memory leak on failure to read stats descriptors
  2022-09-05 10:06 [PATCH] kvm: fix memory leak on failure to read stats descriptors Paolo Bonzini
@ 2022-09-05 10:56 ` Richard Henderson
  2022-09-05 10:59 ` Marc-André Lureau
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2022-09-05 10:56 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel

On 9/5/22 11:06, Paolo Bonzini wrote:
> Reported by Coverity as CID 1490142.
> 
> 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 7c8ce18bdd..208b0c74e3 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -3962,6 +3962,7 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
>                      size_desc * kvm_stats_header->num_desc, ret);
>           g_free(descriptors);
>           g_free(kvm_stats_desc);
> +        g_free(kvm_stats_header);
>           return NULL;
>       }

kvm_stats_header should also be freed just above, in the other read failure if block.

Alternately, can StatsDescriptors be reorg'ed as

   typedef struct StatsDescriptors {

       const char *ident; /* cache key, currently the StatsTarget */

       struct kvm_stats_desc *kvm_stats_desc;

-     struct kvm_stats_header *kvm_stats_header;
+     struct kvm_stats_header kvm_stats_header;
       QTAILQ_ENTRY(StatsDescriptors) next;

   } StatsDescriptors;


since it appears that kvm_stats_header has the same lifetime as the descriptor, and is not 
variable sized, like kvm_stats_desc.


r~


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

* Re: [PATCH] kvm: fix memory leak on failure to read stats descriptors
  2022-09-05 10:06 [PATCH] kvm: fix memory leak on failure to read stats descriptors Paolo Bonzini
  2022-09-05 10:56 ` Richard Henderson
@ 2022-09-05 10:59 ` Marc-André Lureau
  1 sibling, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2022-09-05 10:59 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

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

On Mon, Sep 5, 2022 at 2:32 PM Paolo Bonzini <pbonzini@redhat.com> wrote:

> Reported by Coverity as CID 1490142.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@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 7c8ce18bdd..208b0c74e3 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -3962,6 +3962,7 @@ static StatsDescriptors
> *find_stats_descriptors(StatsTarget target, int stats_fd
>                     size_desc * kvm_stats_header->num_desc, ret);
>          g_free(descriptors);
>          g_free(kvm_stats_desc);
> +        g_free(kvm_stats_header);
>          return NULL;
>      }
>      descriptors->kvm_stats_header = kvm_stats_header;
> --
> 2.37.2
>
>
>

-- 
Marc-André Lureau

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

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

end of thread, other threads:[~2022-09-05 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05 10:06 [PATCH] kvm: fix memory leak on failure to read stats descriptors Paolo Bonzini
2022-09-05 10:56 ` Richard Henderson
2022-09-05 10:59 ` 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).