Patchwork net: delete QemuOpts when net_client_init() fails.

login
register
mail settings
Submitter Yoshiaki Tamura
Date June 21, 2010, 1:41 a.m.
Message ID <1277084496-29813-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp>
Download mbox | patch
Permalink /patch/56280/
State New
Headers show

Comments

Yoshiaki Tamura - June 21, 2010, 1:41 a.m.
This fixes the following scenario using QMP.

First, put a bogus argument "foo" to "type", which results in an error.
{"execute": "netdev_add", "arguments": { "type": "foo", "id": "netdev1" } }
Then, call it again with correct argument "user".
{"execute": "netdev_add", "arguments": { "type": "user", "id": "netdev1" } }
This results in "DuplicatedId" error.

Because the first command was invalid, it should be able to reuse the
same "id", and the second command should work.

Reported-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp>
---
 net.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Markus Armbruster - June 21, 2010, 8:28 a.m.
Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp> writes:

> This fixes the following scenario using QMP.
>
> First, put a bogus argument "foo" to "type", which results in an error.
> {"execute": "netdev_add", "arguments": { "type": "foo", "id": "netdev1" } }
> Then, call it again with correct argument "user".
> {"execute": "netdev_add", "arguments": { "type": "user", "id": "netdev1" } }
> This results in "DuplicatedId" error.
>
> Because the first command was invalid, it should be able to reuse the
> same "id", and the second command should work.
>
> Reported-by: Luiz Capitulino <lcapitulino@redhat.com>
> Signed-off-by: Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp>

Looks good.

Patch

diff --git a/net.c b/net.c
index 0703698..a6b75f3 100644
--- a/net.c
+++ b/net.c
@@ -1208,6 +1208,10 @@  int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
     }
 
     res = net_client_init(mon, opts, 1);
+    if (res < 0) {
+        qemu_opts_del(opts);
+    }
+
     return res;
 }