Skip to contentSkip to conversation

vl: fix resource leak with monitor_fdset_add_fd

PATCH Superseded Paolo Bonzini 4 participants 4 messages Mar 13, 2015 – Mar 14, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

---

	v1->v2: line length [Fam], pass &error_abort [Shannon]
---
 vl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
vl.c +5 -2
index eba5d4c..9eae8f9 100644
@@ -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,10 @@ 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,
+                                  &error_abort);
+    g_free(fdinfo);
 
     return 0;
 }
Signature · 1 line
2.3.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paolo Bonzini

monitor_fdset_add_fd returns an AddfdInfo struct (used by the QMP command add_fd). Free it.

---

	v1->v2: line length [Fam], pass &error_abort [Shannon]
---
 vl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 13 lines
vl.c +1 -0
index eba5d4c..9eae8f9 100644
@@ -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 1065

Quoted 7 lines
vl.c +2 -2
@@ -1060,8 +1061,10 @@ 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,

I might have written !!fd_opaque (as cond ? true : false always looks so long), but that's cosmetic and doesn't affect the review.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 29 lines · Eric Blake
Quoted 10 lines · Paolo Bonzini

monitor_fdset_add_fd returns an AddfdInfo struct (used by the QMP command add_fd). Free it.

---

	v1->v2: line length [Fam], pass &error_abort [Shannon]
---
 vl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 15 lines
vl.c +1 -0
index eba5d4c..9eae8f9 100644
@@ -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,10 @@ static int parse_add_fd(QemuOpts *opts, void *opaque)
     }
 
Quoted 9 lines

vl.c static int parse_add_fd(QemuOpts *opts, void *opaque) · line 1065

Quoted 6 lines
vl.c +0 -0
     /* add the duplicate fd, and optionally the opaque string, to

the fd set */

vl.c +2 -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,

I might have written !!fd_opaque (as cond ? true : false always looks so long), but that's cosmetic and doesn't affect the review.

The use of ?: here borders on code obfuscation. Please clean it up.

If you can't stand !!fd_opaque, then use fd_opaque != NULL.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Paolo Bonzini
Quoted 10 lines · Paolo Bonzini

monitor_fdset_add_fd returns an AddfdInfo struct (used by the QMP command add_fd). Free it.

---

	v1->v2: line length [Fam], pass &error_abort [Shannon]
---
 vl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 26 lines
vl.c +5 -2
index eba5d4c..9eae8f9 100644
@@ -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,10 @@ 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,
+                                  &error_abort);
+    g_free(fdinfo);
 
     return 0;
 }
Signature · 2 lines
Thanks,
Shannon