virtio-net: fix the memory leak in rxfilter_notify()
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
@@ -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
Quoted 4 lines · Amos Kong
object_get_canonical_path()returns a gchar*, it should be freeed by the caller.Signed-off-by Amos Kong <[email protected]>
Quoted 9 lines
--- hw/net/virtio-net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/net/virtio-net.c +0
-0
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
-4if (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
Quoted 4 lines · Amos Kong
object_get_canonical_path()returns a gchar*, it should be freeed by the caller.Signed-off-by Amos Kong <[email protected]>
-vlad
Quoted 36 lines
--- hw/net/virtio-net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/net/virtio-net.c +4
-4@@ -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)
Stefan Hajnoczi
AppliedQuoted 7 lines · Amos Kong
object_get_canonical_path()returns a gchar*, it should be freeed by the caller.Signed-off-by Amos Kong <[email protected]>--- hw/net/virtio-net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Thanks, applied to my net tree (will send pull request for QEMU 1.7):
https://github.com/stefanha/qemu/commits/net
Stefan
Quoted 9 lines · Stefan Hajnoczi
Quoted 7 lines · Amos Kong
object_get_canonical_path()returns a gchar*, it should be freeed by the caller.Signed-off-by Amos Kong <[email protected]>--- 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/netStefan
I'd prefer it for my comment to be addressed first ...
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.Signed-off-by Amos Kong <[email protected]>--- 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/netStefan
I'd prefer it for my comment to be addressed first ...
I folded your suggestion into the commit.
Stefan