From: Paolo Bonzini <pbonzini@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>, qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Markus Armbruster" <armbru@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: Thu, 26 Mar 2020 10:42:08 +0100 [thread overview]
Message-ID: <c408ed09-3740-bc5d-2e39-318bb5beff3f@redhat.com> (raw)
In-Reply-To: <20200325184723.2029630-4-marcandre.lureau@redhat.com>
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)
I queued this patch and your other two. Thanks,
Paolo
next prev parent reply other threads:[~2020-03-26 9:43 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 [this message]
2020-03-30 14:48 ` Markus Armbruster
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=c408ed09-3740-bc5d-2e39-318bb5beff3f@redhat.com \
--to=pbonzini@redhat.com \
--cc=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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).