Skip to contentSkip to conversation

vl: fix resource leak with monitor_fdset_add_fd

PATCH In review Paolo Bonzini 4 participants 4 messages Mar 15, 2015 – Mar 19, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v3 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]
        v2->v3: use "!!" instead of "? true : false" [Markus]
---
 vl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
vl.c +4 -2
index eba5d4c..5985680 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,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, fd_opaque,
+                                  &error_abort);
+    g_free(fdinfo);
 
     return 0;
 }
Signature · 1 line
2.3.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Paolo Bonzini

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

Quoted 35 lines

---

	v1->v2: line length [Fam], pass &error_abort [Shannon]
        v2->v3: use "!!" instead of "? true : false" [Markus]
---
 vl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
vl.c +4 -2
index eba5d4c..5985680 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,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, fd_opaque,
+                                  &error_abort);
+    g_free(fdinfo);
 
     return 0;
 }
Signature · 1 line
2.3.0
Reviewed-by on v3 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 25 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]
        v2->v3: use "!!" instead of "? true : false" [Markus]
---
 vl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
vl.c +1 -0
index eba5d4c..5985680 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,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, fd_opaque,
+                                  &error_abort);
+    g_free(fdinfo);
 
     return 0;
 }

Aside: monitor_fdset_add_fd()'s two has_ parameters are rather unnatural.

#3 lore raw
In reply to Paolo Bonzini
Quoted 7 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]
        v2->v3: use "!!" instead of "? true : false" [Markus]

And ofcourse after finding v2 and v3, I applied this v3 one instead of the initial version with a fixup. Well, this boolean thing becomes really ugly... :(

Thanks,

/mjt