[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] hw/arm/cubieboard: make sure SOC object isn't leaked
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH] hw/arm/cubieboard: make sure SOC object isn't leaked |
Date: |
Fri, 6 Mar 2020 11:33:07 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 |
On 3/3/20 10:12 AM, Igor Mammedov wrote:
SOC object returned by object_new() is leaked in current code.
Set SOC parent explicitly to board and then unref to SOC object
to make sure that refererence returned by object_new() is taken
care of.
The SOC object will be kept alive by its parent (machine) and
will be automatically freed when MachineState is destroyed.
Signed-off-by: Igor Mammedov <address@hidden>
Reported-by: Andrew Jones <address@hidden>
---
hw/arm/cubieboard.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
index 089f9a30c1..12f8ac798d 100644
--- a/hw/arm/cubieboard.c
+++ b/hw/arm/cubieboard.c
@@ -30,9 +30,14 @@ static struct arm_boot_info cubieboard_binfo = {
static void cubieboard_init(MachineState *machine)
{
- AwA10State *a10 = AW_A10(object_new(TYPE_AW_A10));
+ AwA10State *a10;
Error *err = NULL;
What about using object_new_with_props similarly to commit e4c81e3a451f?
a10 = AW_A10(object_new_with_props(TYPE_AW_A10, OBJECT(s), "soc",
&err, NULL));
if (err != NULL) {
error_propagate(errp, err);
return;
}
+ a10 = AW_A10(object_new(TYPE_AW_A10));
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(a10),
+ &error_abort);
+ object_unref(OBJECT(a10));
+
object_property_set_int(OBJECT(&a10->emac), 1, "phy-addr", &err);
if (err != NULL) {
error_reportf_err(err, "Couldn't set phy address: ");