Skip to contentSkip to conversation

hw/s390x/ccw-device: Fix memory leak in loadparm setter

PATCH In review Kevin Wolf 4 participants 4 messages Jun 25, 2025

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 hw/s390x/ccw-device: Fix memory leak in loadparm setter

Commit bdf12f2a fixed the setter for the "loadparm" machine property, which gets a string from a visitor, passes it to s390_ipl_fmt_loadparm() and then forgot to free it. It left another instance of the same problem unfixed in the "loadparm" device property. Fix it.

---
 hw/s390x/ccw-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/ccw-device.c +1 -1
index 19c2238f76..8be1813b9e 100644
@@ -57,7 +57,7 @@ static void ccw_device_set_loadparm(Object *obj, Visitor *v,
                                  Error **errp)
 {
     CcwDevice *dev = CCW_DEVICE(obj);
-    char *val;
+    g_autofree char *val = NULL;
     int index;
 
     index = object_property_get_int(obj, "bootindex", NULL);
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Kevin Wolf

Commit bdf12f2a fixed the setter for the "loadparm" machine property, which gets a string from a visitor, passes it to s390_ipl_fmt_loadparm() and then forgot to free it. It left another instance of the same problem unfixed in the "loadparm" device property. Fix it.

---
 hw/s390x/ccw-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Tested-by on v1 1/1
#2 lore raw
In reply to Kevin Wolf
Quoted 15 lines · Kevin Wolf

Commit bdf12f2a fixed the setter for the "loadparm" machine property, which gets a string from a visitor, passes it to s390_ipl_fmt_loadparm() and then forgot to free it. It left another instance of the same problem unfixed in the "loadparm" device property. Fix it.

---
  hw/s390x/ccw-device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/ccw-device.c +0 -0
index 19c2238f76..8be1813b9e 100644

hw/s390x/ccw-device.c static void ccw_device_set_loadparm(Object *obj, Visitor *v, · line 61

Quoted 6 lines
hw/s390x/ccw-device.c +1 -1
@@ -57,7 +57,7 @@ static void ccw_device_set_loadparm(Object *obj, Visitor *v,
                                   Error **errp)
  {
      CcwDevice *dev = CCW_DEVICE(obj);
-    char *val;
+    g_autofree char *val = NULL;
      int index;

I was able to reproduce the leak with a command line like this:

valgrind --trace-children=yes --track-origins=yes --leak-check=full \
--show-leak-kinds=definite ./qemu-system-s390x -nographic -accel kvm \
-drive if=none,file=/tmp/disk0.qcow2,format=qcow2,id=drive_image1 \
-device virtio-blk-ccw,drive="drive_image1",bootindex=0,loadparm=4 \
-device virtio-scsi-ccw

And I can confirm that your patch fixes the issue, thank you!

I'll queue it for my next pull request.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Kevin Wolf
Quoted 6 lines · On Wed, 25 Jun 2025 10:27:51 +0200 Kevin Wolf <[email protected]> wrote:

Commit bdf12f2a fixed the setter for the "loadparm" machine property, which gets a string from a visitor, passes it to s390_ipl_fmt_loadparm() and then forgot to free it. It left another instance of the same problem unfixed in the "loadparm" device property. Fix it.