Skip to contentSkip to conversation

qbus: fix memory leak in qbus_free()

PATCH Applied Isaku Yamahata 3 participants 5 messages May 27, 2010 – Jun 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qbus: fix memory leak in qbus_free()

BusState::name is allocated in qbus_create_inplace(). So it should be freed by qbus_free().

---
 hw/qdev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/qdev.c +1 -0
index af17486..2845af5 100644
@@ -700,6 +700,7 @@ void qbus_free(BusState *bus)
         QLIST_REMOVE(bus, sibling);
         bus->parent->num_child_bus--;
     }
+    qemu_free((void*)bus->name);
     if (bus->qdev_allocated) {
         qemu_free(bus);
     }
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 2 lines · Isaku Yamahata

BusState::name is allocated in qbus_create_inplace(). So it should be freed by qbus_free().

Correct.

Quoted 10 lines
---
 hw/qdev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/qdev.c +0 -0
index af17486..2845af5 100644

hw/qdev.c void qbus_free(BusState *bus) · line 706

Quoted 7 lines
hw/qdev.c +1 -0
@@ -700,6 +700,7 @@ void qbus_free(BusState *bus)
         QLIST_REMOVE(bus, sibling);
         bus->parent->num_child_bus--;
     }
+    qemu_free((void*)bus->name);
     if (bus->qdev_allocated) {
         qemu_free(bus);
     }

Ugly, superfluous cast to void *.

Thanks!

#2 lore raw
Quoted 12 lines · Markus Armbruster
Quoted 2 lines · Isaku Yamahata

BusState::name is allocated in qbus_create_inplace(). So it should be freed by qbus_free().

Correct.

Quoted 5 lines
---
 hw/qdev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 14 lines

hw/qdev.c void qbus_free(BusState *bus) · line 706

Quoted 12 lines
hw/qdev.c +1 -0
index af17486..2845af5 100644
@@ -700,6 +700,7 @@ void qbus_free(BusState *bus)
         QLIST_REMOVE(bus, sibling);
         bus->parent->num_child_bus--;
     }
+    qemu_free((void*)bus->name);
     if (bus->qdev_allocated) {
         qemu_free(bus);
     }

Ugly, superfluous cast to void *.

BusState::name is const char* so that the cast is necessary to drop const qualifier. Otherwise gcc complains as follows.

qemu/hw/qdev.c: In function 'qbus_free':
qemu/hw/qdev.c:657: error: passing argument 1 of 'qemu_free' discards qualifiers from pointer target type

Signature · 1 line
yamahata
#3 lore raw
Quoted 28 lines · Isaku Yamahata
Quoted 12 lines · Markus Armbruster
Quoted 2 lines · Isaku Yamahata

BusState::name is allocated in qbus_create_inplace(). So it should be freed by qbus_free().

Correct.

Quoted 5 lines
---
 hw/qdev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 14 lines

hw/qdev.c void qbus_free(BusState *bus) · line 706

Quoted 12 lines
hw/qdev.c +1 -0
index af17486..2845af5 100644
@@ -700,6 +700,7 @@ void qbus_free(BusState *bus)
         QLIST_REMOVE(bus, sibling);
         bus->parent->num_child_bus--;
     }
+    qemu_free((void*)bus->name);
     if (bus->qdev_allocated) {
         qemu_free(bus);
     }

Ugly, superfluous cast to void *.

Quoted 5 lines

BusState::name is const char* so that the cast is necessary to drop const qualifier. Otherwise gcc complains as follows.

qemu/hw/qdev.c: In function 'qbus_free':
qemu/hw/qdev.c:657: error: passing argument 1 of 'qemu_free' discards qualifiers from pointer target type

You're right. I keep suppressing all the silly trouble caused by const. Sorry for the noise.

Applied
#4 lore raw
In reply to Isaku Yamahata

Thanks, applied.

Quoted 24 lines · Isaku Yamahata

BusState::name is allocated in qbus_create_inplace(). So it should be freed by qbus_free().

---
 hw/qdev.c |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
hw/qdev.c +1 -1
index af17486..2845af5 100644
@@ -700,6 +700,7 @@ void qbus_free(BusState *bus)
         QLIST_REMOVE(bus, sibling);
         bus->parent->num_child_bus--;
     }
+    qemu_free((void*)bus->name);
     if (bus->qdev_allocated) {
         qemu_free(bus);
     }
--

1.6.6.1