Xen-Devel Archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/xen: Fix memory leak in libxenstore_open() for Xen
@ 2023-04-04 18:24 David Woodhouse
  2023-04-04 18:28 ` Peter Maydell
  0 siblings, 1 reply; 2+ messages in thread
From: David Woodhouse @ 2023-04-04 18:24 UTC (permalink / raw
  To: qemu-devel
  Cc: xen-devel, Paul Durrant, Anthony Perard, Stefano Stabellini,
	Peter Maydell

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

From: David Woodhouse <dwmw@amazon.co.uk>

There was a superfluous allocation of the XS handle, leading to it
being leaked on both the error path and the success path (where it gets
allocated again).

Spotted by Coverity (CID 1508098).

Fixes: ba2a92db1ff6 ("hw/xen: Add xenstore operations to allow redirection to internal emulation")
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 hw/xen/xen-operations.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c
index 4b78fbf4bd..3d213d28df 100644
--- a/hw/xen/xen-operations.c
+++ b/hw/xen/xen-operations.c
@@ -287,7 +287,7 @@ static void watch_event(void *opaque)
 static struct qemu_xs_handle *libxenstore_open(void)
 {
     struct xs_handle *xsh = xs_open(0);
-    struct qemu_xs_handle *h = g_new0(struct qemu_xs_handle, 1);
+    struct qemu_xs_handle *h;
 
     if (!xsh) {
         return NULL;
-- 
2.34.1



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]

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

* Re: [PATCH] hw/xen: Fix memory leak in libxenstore_open() for Xen
  2023-04-04 18:24 [PATCH] hw/xen: Fix memory leak in libxenstore_open() for Xen David Woodhouse
@ 2023-04-04 18:28 ` Peter Maydell
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Maydell @ 2023-04-04 18:28 UTC (permalink / raw
  To: David Woodhouse
  Cc: qemu-devel, xen-devel, Paul Durrant, Anthony Perard,
	Stefano Stabellini

On Tue, 4 Apr 2023 at 19:25, David Woodhouse <dwmw2@infradead.org> wrote:
>
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> There was a superfluous allocation of the XS handle, leading to it
> being leaked on both the error path and the success path (where it gets
> allocated again).
>
> Spotted by Coverity (CID 1508098).
>
> Fixes: ba2a92db1ff6 ("hw/xen: Add xenstore operations to allow redirection to internal emulation")
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
>  hw/xen/xen-operations.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c
> index 4b78fbf4bd..3d213d28df 100644
> --- a/hw/xen/xen-operations.c
> +++ b/hw/xen/xen-operations.c
> @@ -287,7 +287,7 @@ static void watch_event(void *opaque)
>  static struct qemu_xs_handle *libxenstore_open(void)
>  {
>      struct xs_handle *xsh = xs_open(0);
> -    struct qemu_xs_handle *h = g_new0(struct qemu_xs_handle, 1);
> +    struct qemu_xs_handle *h;
>
>      if (!xsh) {
>          return NULL;
> --
> 2.34.1

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


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

end of thread, other threads:[~2023-04-04 18:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04 18:24 [PATCH] hw/xen: Fix memory leak in libxenstore_open() for Xen David Woodhouse
2023-04-04 18:28 ` Peter Maydell

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 read-only IMAP folder(s) and NNTP newsgroup(s).