* [PATCH v2] kvm: fix memory leak on failure to read stats descriptors
@ 2022-09-05 12:39 Paolo Bonzini
2022-09-05 15:57 ` Richard Henderson
2022-09-05 21:32 ` Philippe Mathieu-Daudé via
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-09-05 12:39 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, Richard Henderson
Reported by Coverity as CID 1490142. Since the size is constant and the
lifetime is the same as the StatsDescriptors struct, embed the struct
directly instead of using a separate allocation.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
accel/kvm/kvm-all.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 7c8ce18bdd..5acab1767f 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -3908,7 +3908,7 @@ exit:
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;
@@ -3939,7 +3939,7 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
descriptors = g_new0(StatsDescriptors, 1);
/* Read stats header */
- kvm_stats_header = g_malloc(sizeof(*kvm_stats_header));
+ kvm_stats_header = &descriptors->kvm_stats_header;
ret = read(stats_fd, kvm_stats_header, sizeof(*kvm_stats_header));
if (ret != sizeof(*kvm_stats_header)) {
error_setg(errp, "KVM stats: failed to read stats header: "
@@ -3964,7 +3964,6 @@ static StatsDescriptors *find_stats_descriptors(StatsTarget target, int stats_fd
g_free(kvm_stats_desc);
return NULL;
}
- descriptors->kvm_stats_header = kvm_stats_header;
descriptors->kvm_stats_desc = kvm_stats_desc;
descriptors->ident = ident;
QTAILQ_INSERT_TAIL(&stats_descriptors, descriptors, next);
@@ -3989,7 +3988,7 @@ static void query_stats(StatsResultList **result, StatsTarget target,
return;
}
- kvm_stats_header = descriptors->kvm_stats_header;
+ kvm_stats_header = &descriptors->kvm_stats_header;
kvm_stats_desc = descriptors->kvm_stats_desc;
size_desc = sizeof(*kvm_stats_desc) + kvm_stats_header->name_size;
@@ -4054,7 +4053,7 @@ static void query_stats_schema(StatsSchemaList **result, StatsTarget target,
return;
}
- kvm_stats_header = descriptors->kvm_stats_header;
+ kvm_stats_header = &descriptors->kvm_stats_header;
kvm_stats_desc = descriptors->kvm_stats_desc;
size_desc = sizeof(*kvm_stats_desc) + kvm_stats_header->name_size;
--
2.37.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kvm: fix memory leak on failure to read stats descriptors
2022-09-05 12:39 [PATCH v2] kvm: fix memory leak on failure to read stats descriptors Paolo Bonzini
@ 2022-09-05 15:57 ` Richard Henderson
2022-09-05 21:32 ` Philippe Mathieu-Daudé via
1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2022-09-05 15:57 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: marcandre.lureau
On 9/5/22 13:39, Paolo Bonzini wrote:
> Reported by Coverity as CID 1490142. Since the size is constant and the
> lifetime is the same as the StatsDescriptors struct, embed the struct
> directly instead of using a separate allocation.
>
> Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
> ---
> accel/kvm/kvm-all.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Thanks,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kvm: fix memory leak on failure to read stats descriptors
2022-09-05 12:39 [PATCH v2] kvm: fix memory leak on failure to read stats descriptors Paolo Bonzini
2022-09-05 15:57 ` Richard Henderson
@ 2022-09-05 21:32 ` Philippe Mathieu-Daudé via
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-05 21:32 UTC (permalink / raw)
To: Paolo Bonzini
Cc: qemu-devel@nongnu.org Developers, Marc-André Lureau,
Richard Henderson
On Mon, Sep 5, 2022 at 3:28 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Reported by Coverity as CID 1490142. Since the size is constant and the
> lifetime is the same as the StatsDescriptors struct, embed the struct
> directly instead of using a separate allocation.
>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> accel/kvm/kvm-all.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-05 21:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05 12:39 [PATCH v2] kvm: fix memory leak on failure to read stats descriptors Paolo Bonzini
2022-09-05 15:57 ` Richard Henderson
2022-09-05 21:32 ` Philippe Mathieu-Daudé via
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).