Skip to contentSkip to conversation

virtio-net: fix the memory leak in rxfilter_notify()

PATCH Applied Amos Kong 5 participants 6 messages Nov 18, 2013 – Nov 19, 2013

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 virtio-net: fix the memory leak in rxfilter_notify()

object_get_canonical_path() returns a gchar*, it should be freeed by the caller.

---
 hw/net/virtio-net.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +4 -4
index 613f144..2b2fb57 100644
@@ -198,15 +198,14 @@ static void rxfilter_notify(NetClientState *nc)
 {
     QObject *event_data;
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    gchar *path = object_get_canonical_path(OBJECT(n->qdev));
 
     if (nc->rxfilter_notify_enabled) {
         if (n->netclient_name) {
             event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }",
-                                    n->netclient_name,
-                                    object_get_canonical_path(OBJECT(n->qdev)));
+                                    n->netclient_name, path);
         } else {
-            event_data = qobject_from_jsonf("{ 'path': %s }",
-                                    object_get_canonical_path(OBJECT(n->qdev)));
+            event_data = qobject_from_jsonf("{ 'path': %s }", path);
         }
         monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data);
         qobject_decref(event_data);
@@ -214,6 +213,7 @@ static void rxfilter_notify(NetClientState *nc)
         /* disable event notification to avoid events flooding */
         nc->rxfilter_notify_enabled = 0;
     }
+    g_free(path);
 }
 
 static char *mac_strdup_printf(const uint8_t *mac)
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Amos Kong

object_get_canonical_path() returns a gchar*, it should be freeed by the caller.

Quoted 9 lines
---
 hw/net/virtio-net.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +0 -0
index 613f144..2b2fb57 100644

hw/net/virtio-net.c static void rxfilter_notify(NetClientState *nc) · line 203

Quoted 6 lines
hw/net/virtio-net.c +1 -0
@@ -198,15 +198,14 @@ static void rxfilter_notify(NetClientState *nc)
 {
     QObject *event_data;
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    gchar *path = object_get_canonical_path(OBJECT(n->qdev));
 
     if (nc->rxfilter_notify_enabled) {

It would be a bit nicer to put gchar *path within this scope.

Quoted 22 lines
hw/net/virtio-net.c +3 -4
         if (n->netclient_name) {
             event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }",
-                                    n->netclient_name,
-                                    object_get_canonical_path(OBJECT(n->qdev)));
+                                    n->netclient_name, path);
         } else {
-            event_data = qobject_from_jsonf("{ 'path': %s }",
-                                    object_get_canonical_path(OBJECT(n->qdev)));
+            event_data = qobject_from_jsonf("{ 'path': %s }", path);
         }
         monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data);
         qobject_decref(event_data);
@@ -214,6 +213,7 @@ static void rxfilter_notify(NetClientState *nc)
         /* disable event notification to avoid events flooding */
         nc->rxfilter_notify_enabled = 0;
     }
+    g_free(path);
 }
 
 static char *mac_strdup_printf(const uint8_t *mac)
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Amos Kong
Quoted 4 lines · Amos Kong

object_get_canonical_path() returns a gchar*, it should be freeed by the caller.

-vlad

Quoted 36 lines
---
 hw/net/virtio-net.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +4 -4
index 613f144..2b2fb57 100644
@@ -198,15 +198,14 @@ static void rxfilter_notify(NetClientState *nc)
 {
     QObject *event_data;
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    gchar *path = object_get_canonical_path(OBJECT(n->qdev));
 
     if (nc->rxfilter_notify_enabled) {
         if (n->netclient_name) {
             event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }",
-                                    n->netclient_name,
-                                    object_get_canonical_path(OBJECT(n->qdev)));
+                                    n->netclient_name, path);
         } else {
-            event_data = qobject_from_jsonf("{ 'path': %s }",
-                                    object_get_canonical_path(OBJECT(n->qdev)));
+            event_data = qobject_from_jsonf("{ 'path': %s }", path);
         }
         monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data);
         qobject_decref(event_data);
@@ -214,6 +213,7 @@ static void rxfilter_notify(NetClientState *nc)
         /* disable event notification to avoid events flooding */
         nc->rxfilter_notify_enabled = 0;
     }
+    g_free(path);
 }
 
 static char *mac_strdup_printf(const uint8_t *mac)
#4 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 7 lines · Amos Kong

object_get_canonical_path() returns a gchar*, it should be freeed by the caller.

---
 hw/net/virtio-net.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 4 lines

Thanks, applied to my net tree (will send pull request for QEMU 1.7):
https://github.com/stefanha/qemu/commits/net

Stefan

I'd prefer it for my comment to be addressed first ...

#5 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Stefan Hajnoczi
Quoted 7 lines · Amos Kong

object_get_canonical_path() returns a gchar*, it should be freeed by the caller.

---
 hw/net/virtio-net.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 6 lines
Quoted 4 lines

Thanks, applied to my net tree (will send pull request for QEMU 1.7):
https://github.com/stefanha/qemu/commits/net

Stefan

I'd prefer it for my comment to be addressed first ...

I folded your suggestion into the commit.

Stefan