diff options
author | Eric Blake <eblake@redhat.com> | 2021-01-13 16:10:13 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2021-01-28 08:08:45 +0100 |
commit | 95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (patch) | |
tree | 76d842228434aa8ac1dc10f8fcc4bfc5cce422d5 /monitor | |
parent | c3033fd372fdaf5b89190136a74b3d78880b85d6 (diff) |
qapi: More complex uses of QAPI_LIST_APPEND
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>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210113221013.390592-6-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Flawed change to qmp_guest_network_get_interfaces() dropped]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/hmp-cmds.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 529f18099e..a48bc1e904 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1706,7 +1706,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 = NULL; + 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; @@ -1723,16 +1724,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; @@ -1741,16 +1733,18 @@ 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); + v = NULL; if (!*separator) { break; @@ -1762,6 +1756,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); out: + qapi_free_KeyValue(v); qapi_free_KeyValueList(head); return; |