Skip to contentSkip to conversation

hw/xen: Fix memory leak in libxenstore_open() for Xen

PATCH In review David Woodhouse 2 participants 2 messages Apr 4, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/xen: Fix memory leak in libxenstore_open() for Xen

From: David Woodhouse <[email protected]>

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")
---
 hw/xen/xen-operations.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen-operations.c +1 -1
index 4b78fbf4bd..3d213d28df 100644
@@ -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;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · David Woodhouse

From: David Woodhouse <[email protected]>

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")
---
 hw/xen/xen-operations.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen-operations.c +1 -2
index 4b78fbf4bd..3d213d28df 100644
@@ -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;
--
Quoted 1 line

2.34.1

thanks
-- PMM