qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"open list:GLUSTER" <integration@gluster.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"open list:GLUSTER" <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	armbru@redhat.com, "Jason Wang" <jasowang@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	qemu-devel@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>
Subject: Re: [PATCH v2 7/7] qapi: More complex uses of QAPI_LIST_APPEND
Date: Mon, 16 Nov 2020 07:27:49 -0600	[thread overview]
Message-ID: <55fccf13-d431-3986-f7f8-e6b8ca02cfde@redhat.com> (raw)
In-Reply-To: <20201113193903.GX3251@work-vm>

On 11/13/20 1:39 PM, Dr. David Alan Gilbert wrote:
> * Eric Blake (eblake@redhat.com) wrote:
>> These cases require a bit more thought to review; in each case, the
>> code was appending to a list, but not with a FOOList **tail variable.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>> ---

> 
> <snip>
> 

>> +++ b/monitor/hmp-cmds.c
>> @@ -1699,7 +1699,8 @@ void hmp_closefd(Monitor *mon, const QDict *qdict)
>>  void hmp_sendkey(Monitor *mon, const QDict *qdict)
>>  {
>>      const char *keys = qdict_get_str(qdict, "keys");
>> -    KeyValueList *keylist, *head = NULL, *tmp = NULL;
>> +    KeyValue *v;
>> +    KeyValueList *head = NULL, **tail = &head;
>>      int has_hold_time = qdict_haskey(qdict, "hold-time");
>>      int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
>>      Error *err = NULL;
>> @@ -1716,16 +1717,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
>>              keyname_len = 4;
>>          }
>>
>> -        keylist = g_malloc0(sizeof(*keylist));
>> -        keylist->value = g_malloc0(sizeof(*keylist->value));
>> -
>> -        if (!head) {
>> -            head = keylist;
>> -        }
>> -        if (tmp) {
>> -            tmp->next = keylist;
>> -        }
>> -        tmp = keylist;
>> +        v = g_malloc0(sizeof(*v));
>>
>>          if (strstart(keys, "0x", NULL)) {
>>              char *endp;
>> @@ -1734,16 +1726,17 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
>>              if (endp != keys + keyname_len) {
>>                  goto err_out;
>>              }
>> -            keylist->value->type = KEY_VALUE_KIND_NUMBER;
>> -            keylist->value->u.number.data = value;
>> +            v->type = KEY_VALUE_KIND_NUMBER;
>> +            v->u.number.data = value;
>>          } else {
>>              int idx = index_from_key(keys, keyname_len);
>>              if (idx == Q_KEY_CODE__MAX) {
>>                  goto err_out;
>>              }
>> -            keylist->value->type = KEY_VALUE_KIND_QCODE;
>> -            keylist->value->u.qcode.data = idx;
>> +            v->type = KEY_VALUE_KIND_QCODE;
>> +            v->u.qcode.data = idx;
>>          }
>> +        QAPI_LIST_APPEND(tail, v);
>>
>>          if (!*separator) {
>>              break;
> 
> Don't you need to arrange for 'v' to be free'd in the err_out case?

Good catch.  Pre-patch, the allocation was appended to the list before
it was possible to reach 'goto err_out', but post-patch, the use of a
separate variable and delayed addition to the list matters.  Will fix.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2020-11-16 13:32 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13  1:13 [PATCH v2 0/7] Common macros for QAPI list growth Eric Blake
2020-11-13  1:13 ` [PATCH v2 1/7 for-5.2?] net: Fix memory leak on error Eric Blake
2020-11-16 14:22   ` Markus Armbruster
2020-11-16 14:41     ` Eric Blake
2020-11-13  1:13 ` [PATCH v2 2/7] rocker: Revamp fp_port_get_info Eric Blake
2020-11-17  9:27   ` Markus Armbruster
2020-11-13  1:13 ` [PATCH v2 3/7] migration: Refactor migrate_cap_add Eric Blake
2020-11-17  9:45   ` Markus Armbruster
2020-11-13  1:13 ` [PATCH v2 4/7] qapi: Use QAPI_LIST_PREPEND() where possible Eric Blake
2020-11-17 10:20   ` Markus Armbruster
2020-11-17 11:45   ` Stefan Hajnoczi
2020-11-13  1:13 ` [PATCH v2 5/7] qapi: Introduce QAPI_LIST_APPEND Eric Blake
2020-11-17 12:51   ` Markus Armbruster
2020-11-18  0:41     ` Eric Blake
2020-11-18  6:21       ` Markus Armbruster
2020-11-13  1:13 ` [PATCH v2 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases Eric Blake
2020-11-13  1:13 ` [PATCH v2 7/7] qapi: More complex uses of QAPI_LIST_APPEND Eric Blake
2020-11-13 19:39   ` Dr. David Alan Gilbert
2020-11-16 13:27     ` Eric Blake [this message]
2020-11-19  8:50   ` Markus Armbruster
2020-12-04 22:54     ` Eric Blake
2020-11-19  9:28 ` [PATCH v2 0/7] Common macros for QAPI list growth Markus Armbruster
2020-12-19  9:43   ` 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=55fccf13-d431-3986-f7f8-e6b8ca02cfde@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=integration@gluster.org \
    --cc=jasowang@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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).