diff mbox

monitor: fix qmp_getfd() fd leak in error case

Message ID 1398340698-3685-1-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi April 24, 2014, 11:58 a.m. UTC
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>
---
 monitor.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Markus Armbruster April 25, 2014, 7 a.m. UTC | #1
Stefan Hajnoczi <stefanha@redhat.com> writes:

> 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>
Luiz Capitulino April 25, 2014, 3:42 p.m. UTC | #2
On Thu, 24 Apr 2014 13:58:18 +0200
Stefan Hajnoczi <stefanha@redhat.com> wrote:

> 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>

Applied to the qmp branch, thanks.

> ---
>  monitor.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/monitor.c b/monitor.c
> index 342e83b..7506ff5 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2254,6 +2254,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;
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 342e83b..7506ff5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2254,6 +2254,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;