vl: fix resource leak with monitor_fdset_add_fd
PATCH 1/1 vl: fix resource leak with monitor_fdset_add_fd
monitor_fdset_add_fd returns an AddfdInfo struct (used by the QMP command add_fd). Free it.
--- vl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
vl.c +4 -2
@@ -1011,6 +1011,7 @@ static int parse_add_fd(QemuOpts *opts, void *opaque)int fd, dupfd, flags;int64_t fdset_id;const char *fd_opaque =NULL ; +AddfdInfo *fdinfo; fd =qemu_opt_get_number (opts,"fd" ,-1 ); fdset_id =qemu_opt_get_number (opts,"set" ,-1 );
@@ -1060,8 +1061,9 @@ static int parse_add_fd(QemuOpts *opts, void *opaque) }/* add the duplicate fd, and optionally the opaque string, to the fd set */ -monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, - fd_opaque,NULL ); + fdinfo =monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, + fd_opaque,NULL ); +g_free (fdinfo);return 0 ; }
Signature · 1 line
2.3.0
Quoted 7 lines · Paolo Bonzini
monitor_fdset_add_fdreturns an AddfdInfo struct (used by the QMP commandadd_fd). Free it.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 21 lines · Paolo Bonzini
monitor_fdset_add_fdreturns an AddfdInfo struct (used by the QMP commandadd_fd). Free it.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)vl.c +1
-0@@ -1011,6 +1011,7 @@ static int parse_add_fd(QemuOpts *opts, void *opaque)int fd, dupfd, flags;int64_t fdset_id;const char *fd_opaque =NULL ; +AddfdInfo *fdinfo; fd =qemu_opt_get_number (opts,"fd" ,-1 ); fdset_id =qemu_opt_get_number (opts,"set" ,-1 );
vl.c static int parse_add_fd(QemuOpts *opts, void *opaque) · line 1064
Quoted 6 lines
vl.c +1
-2@@ -1060,8 +1061,9 @@ static int parse_add_fd(QemuOpts *opts, void *opaque) }/* add the duplicate fd, and optionally the opaque string, to the fd set */ -monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, - fd_opaque,NULL ); + fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
Too long a line, with that fixed,
Quoted 9 lines
vl.c +2
-0+ fd_opaque, NULL); +g_free (fdinfo);return 0 ; }Signature · 1 line
2.3.0
This series passed Patchew automatic testing, but there are some warnings.
Find the log fragments below, or open the following URL to see the full log:
http://qemu.patchew.org/testing/log/<[email protected]>
----------8<---------
=== Starting docker ===
Copying test script "/home/patchew/tests/qemu-devel.sh"
Starting docker...
docker run --net=none -v /var/tmp/patchew-tester/tmpELr8N5:/var/tmp/patchew-test patchew:fedora-20 timeout 3600 /var/tmp/patchew-test/qemu-devel.sh /var/tmp/patchew-test
*** Testing 'coding style check' ***
Checking 0001-vl--fix-resource-leak-with-monitor_fdset_add_fd.patch command failed with exit code 0
$@
WARNING: line over 80 characters
#27: FILE: vl.c:1064:
+ fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false,
total: 0 errors, 1 warnings, 18 lines checked
0001-vl--fix-resource-leak-with-monitor_fdset_add_fd.patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
*** Testing 'configure' ***
Install prefix /usr/local BIOS directory /usr/local/share/qemu binary directory /usr/local/bin
library directory /usr/local/lib
module directory /usr/local/lib/qemu
libexec directory /usr/local/libexec
Quoted 23 lines · Paolo Bonzini
monitor_fdset_add_fdreturns an AddfdInfo struct (used by the QMP commandadd_fd). Free it.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)vl.c +1
-0@@ -1011,6 +1011,7 @@ static int parse_add_fd(QemuOpts *opts, void *opaque)int fd, dupfd, flags;int64_t fdset_id;const char *fd_opaque =NULL ; +AddfdInfo *fdinfo; fd =qemu_opt_get_number (opts,"fd" ,-1 ); fdset_id =qemu_opt_get_number (opts,"set" ,-1 );@@ -1060,8 +1061,9 @@ static int parse_add_fd(QemuOpts *opts, void *opaque) }
vl.c static int parse_add_fd(QemuOpts *opts, void *opaque) · line 1069
Quoted 10 lines
vl.c +3
-2/* add the duplicate fd, and optionally the opaque string, to the fd set */ -monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, - fd_opaque,NULL ); + fdinfo =monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, + fd_opaque,NULL ); +g_free (fdinfo);return 0 ; }
Hi Paolo,
Not about the resource leak, but I think we should check fdinfo == NULL and return -1. Then when error occurs, qemu will exit. Besides we should pass a meaningful errp not NULL. So qemu can report the error reason. Right?
Signature · 2 lines
Thanks, Shannon
Quoted 6 lines · Shannon Zhao
Quoted 6 lines
Quoted 6 lines
vl.c +3
-2-monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, - fd_opaque,NULL ); + fdinfo =monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, + fd_opaque,NULL ); +g_free (fdinfo);
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
return 0;}
Hi Paolo,
Not about the resource leak, but I think we should check fdinfo == NULL and return -1. Then when error occurs, qemu will exit. Besides we should pass a meaningful errp not NULL. So qemu can report the error reason. Right?
It cannot fail here, so another possibility could be to pass &error_abort.
Paolo
Michael Tokarev
AppliedQuoted 2 lines · Paolo Bonzini
monitor_fdset_add_fdreturns an AddfdInfo struct (used by the QMP commandadd_fd). Free it.
Applied to -trivial, with a tiny change:
vl.c static int parse_add_fd(QemuOpts *opts, void *opaque) · line 1065
Quoted 2 lines
vl.c +2
-0+ fdinfo =monitor_fdset_add_fd (dupfd, true, fdset_id, fd_opaque ? true : false, + fd_opaque,NULL );
fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id,
fd_opaque ? true : false, fd_opaque, NULL);
(this fits in 80 chars a line). Another variant is to use `fd_opaque != NULL' here instead of this ?true:false construct.
Thanks,
/mjt