object_new() returns cpu with refcnt == 1 and after realize
refcnt == 2*. s390x_new_cpu() as an owner of the first refcnt
should have released it on exit in both cases (on error and
success) to avoid it leaking. Do so for both cases.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
target/s390x/helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/s390x/helper.c b/target/s390x/helper.c
index 97adbcc..64d4c48 100644
--- a/target/s390x/helper.c
+++ b/target/s390x/helper.c
@@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)
object_property_set_bool(OBJECT(cpu), true, "realized", &err);
out:
+ object_unref(OBJECT(cpu));
if (err) {
error_propagate(errp, err);
- object_unref(OBJECT(cpu));
cpu = NULL;
}
return cpu;
--
2.7.4
On Tue, 17 Oct 2017 15:41:19 +0200
Igor Mammedov <imammedo@redhat.com> wrote:
> object_new() returns cpu with refcnt == 1 and after realize
> refcnt == 2*. s390x_new_cpu() as an owner of the first refcnt
> should have released it on exit in both cases (on error and
> success) to avoid it leaking. Do so for both cases.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> target/s390x/helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/s390x/helper.c b/target/s390x/helper.c
> index 97adbcc..64d4c48 100644
> --- a/target/s390x/helper.c
> +++ b/target/s390x/helper.c
> @@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)
> object_property_set_bool(OBJECT(cpu), true, "realized", &err);
>
> out:
> + object_unref(OBJECT(cpu));
> if (err) {
> error_propagate(errp, err);
> - object_unref(OBJECT(cpu));
> cpu = NULL;
> }
> return cpu;
Looks reasonable.
On Tue, 17 Oct 2017 15:41:19 +0200
Igor Mammedov <imammedo@redhat.com> wrote:
> object_new() returns cpu with refcnt == 1 and after realize
> refcnt == 2*. s390x_new_cpu() as an owner of the first refcnt
> should have released it on exit in both cases (on error and
> success) to avoid it leaking. Do so for both cases.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> target/s390x/helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/s390x/helper.c b/target/s390x/helper.c
> index 97adbcc..64d4c48 100644
> --- a/target/s390x/helper.c
> +++ b/target/s390x/helper.c
> @@ -80,9 +80,9 @@ S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)
> object_property_set_bool(OBJECT(cpu), true, "realized", &err);
>
> out:
> + object_unref(OBJECT(cpu));
> if (err) {
> error_propagate(errp, err);
> - object_unref(OBJECT(cpu));
> cpu = NULL;
> }
> return cpu;
Thanks, applied.
© 2016 - 2026 Red Hat, Inc.