All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH for-5.0 3/3] object-add: don't create return value if failed
Date: Mon, 30 Mar 2020 16:48:59 +0200	[thread overview]
Message-ID: <87wo71ucdg.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <c408ed09-3740-bc5d-2e39-318bb5beff3f@redhat.com> (Paolo Bonzini's message of "Thu, 26 Mar 2020 10:42:08 +0100")

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 25/03/20 19:47, Marc-André Lureau wrote:
>> If object-add failed, no need to create a return value that may later
>> be leaked.
>> 
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  qom/qom-qmp-cmds.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
>> index 435193b036..6bd137ccbf 100644
>> --- a/qom/qom-qmp-cmds.c
>> +++ b/qom/qom-qmp-cmds.c
>> @@ -287,8 +287,8 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
>>      visit_free(v);
>>      if (obj) {
>>          object_unref(obj);
>> +        *ret_data = QOBJECT(qdict_new());
>>      }
>> -    *ret_data = QOBJECT(qdict_new());
>>  }
>>  
>>  void qmp_object_del(const char *id, Error **errp)
>> 
>
> It can be slightly simplified:
>
> ------------------- 8< ----------------------
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH] object-add: don't create return value if failed
>     
> No need to return an empty value from object-add (it would also leak
> if the command failed).  While at it, remove the "if" around object_unref
> since object_unref handles NULL arguments just fine.
>     
> Reported-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
> index 435193b036..e47ebe8ed1 100644
> --- a/qom/qom-qmp-cmds.c
> +++ b/qom/qom-qmp-cmds.c
> @@ -285,10 +285,7 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
>      v = qobject_input_visitor_new(QOBJECT(qdict));
>      obj = user_creatable_add_type(type, id, qdict, v, errp);
>      visit_free(v);
> -    if (obj) {
> -        object_unref(obj);
> -    }
> -    *ret_data = QOBJECT(qdict_new());
> +    object_unref(obj);
>  }
>  
>  void qmp_object_del(const char *id, Error **errp)

Yes, that's better.

Reviewed-by: Markus Armbruster <armbru@redhat.com>

> I queued this patch and your other two.  Thanks,
>
> Paolo



      reply	other threads:[~2020-03-30 14:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 18:47 [PATCH for-5.0 0/3] Memory leak fixes Marc-André Lureau
2020-03-25 18:47 ` [PATCH for-5.0 1/3] migration: fix cleanup_bh leak on resume Marc-André Lureau
2020-03-26  2:40   ` Juan Quintela
2020-03-25 18:47 ` [PATCH for-5.0 2/3] qmp: fix leak on callbacks that return both value and error Marc-André Lureau
2020-03-30 14:59   ` Markus Armbruster
2020-03-25 18:47 ` [PATCH for-5.0 3/3] object-add: don't create return value if failed Marc-André Lureau
2020-03-25 20:43   ` Philippe Mathieu-Daudé
2020-03-26  9:42   ` Paolo Bonzini
2020-03-30 14:48     ` Markus Armbruster [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wo71ucdg.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.