monitor: fix qmp_getfd() fd leak in error case
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 24 Apr 2014 11:58:18 +0000 (13:58 +0200)
committerLuiz Capitulino <lcapitulino@redhat.com>
Fri, 25 Apr 2014 15:41:41 +0000 (11:41 -0400)
qemu_chr_fe_get_msgfd() transfers ownership of the file descriptor to
the caller.  Therefore all code paths in qmp_getfd() should either
register the file descriptor somewhere or close it.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
monitor.c

index 9ad857820b7fc8b68e906e4528d18131eaa1aef0..1266ba06fb032cb0e7c9dbaa1b6d22cd9047c6b4 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -2228,6 +2228,7 @@ void qmp_getfd(const char *fdname, Error **errp)
     }
 
     if (qemu_isdigit(fdname[0])) {
+        close(fd);
         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
                   "a name not starting with a digit");
         return;