qbus: fix memory leak in qbus_free()
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
@@ -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
Quoted 2 lines · Isaku Yamahata
BusState::nameis allocated inqbus_create_inplace(). So it should be freed byqbus_free().
Correct.
Quoted 10 lines
Signed-off-by Isaku Yamahata <[email protected]>--- hw/qdev.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)hw/qdev.c +0
-0
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!
Quoted 12 lines · Markus Armbruster
Quoted 2 lines · Isaku Yamahata
BusState::nameis allocated inqbus_create_inplace(). So it should be freed byqbus_free().Correct.
Quoted 5 lines
Signed-off-by Isaku Yamahata <[email protected]>--- 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@@ -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
Quoted 28 lines · Isaku Yamahata
Quoted 12 lines · Markus Armbruster
Quoted 2 lines · Isaku Yamahata
BusState::nameis allocated inqbus_create_inplace(). So it should be freed byqbus_free().Correct.
Quoted 5 lines
Signed-off-by Isaku Yamahata <[email protected]>--- 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@@ -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::nameis 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.
Blue Swirl
AppliedThanks, applied.
Quoted 24 lines · Isaku Yamahata
BusState::nameis allocated inqbus_create_inplace(). So it should be freed byqbus_free().Signed-off-by Isaku Yamahata <[email protected]>---
hw/qdev.c | 1 +1 files changed, 1 insertions(+), 0 deletions(-)hw/qdev.c +1
-1@@ -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