Skip to contentSkip to conversation

colo-proxy: fix memory leak

PATCH Superseded Zhang Chen 2 participants 3 messages Oct 10, 2016 – Oct 11, 2016 Networking

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

PATCH 1/1 colo-proxy: fix memory leak

Fix memory leak in colo-compare.c and filter-rewriter.c Report by Coverity.

---
 net/colo-compare.c    | 4 ++--
 net/filter-rewriter.c | 9 +++++----
 2 files changed, 7 insertions(+), 6 deletions(-)
net/colo-compare.c +2 -2
index 22b1da1..47e7ebe 100644
@@ -235,8 +235,8 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
         fprintf(stderr, "Secondary len = %d\n", spkt->size);
         qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
 
-        g_free(sdebug);
-        g_free(ddebug);
+        free(sdebug);
+        free(ddebug);
     }
 
     return res;
net/filter-rewriter.c +5 -4
index 89abe72..396a03c 100644
@@ -75,8 +75,8 @@ static int handle_primary_tcp_pkt(NetFilterState *nf,
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
         trace_colo_filter_rewriter_conn_offset(conn->offset);
-        g_free(sdebug);
-        g_free(ddebug);
+        free(sdebug);
+        free(ddebug);
     }
 
     if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
@@ -123,8 +123,8 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf,
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
         trace_colo_filter_rewriter_conn_offset(conn->offset);
-        g_free(sdebug);
-        g_free(ddebug);
+        free(sdebug);
+        free(ddebug);
     }
 
     if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) {
@@ -162,6 +162,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
 
     iov_to_buf(iov, iovcnt, 0, buf, size);
     pkt = packet_new(buf, size);
+    g_free(buf);
 
     /*
      * if we get tcp packet
Signature · 1 line
2.7.4
#1 lore raw
Quoted 14 lines · Zhang Chen

Fix memory leak in colo-compare.c and filter-rewriter.c Report by Coverity.

---
 net/colo-compare.c    | 4 ++--
 net/filter-rewriter.c | 9 +++++----
 2 files changed, 7 insertions(+), 6 deletions(-)
net/colo-compare.c +0 -0
index 22b1da1..47e7ebe 100644

net/colo-compare.c static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) · line 239

Quoted 7 lines
net/colo-compare.c +2 -2
@@ -235,8 +235,8 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
         fprintf(stderr, "Secondary len = %d\n", spkt->size);
         qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
 
-        g_free(sdebug);
-        g_free(ddebug);
+        free(sdebug);
+        free(ddebug);

Uggh. We should fix the original allocations of sdebug and ddebug to use g_strdup_printf() rather than strdup(), so that we are using a consistent allocator throughout. Or even improve this code to use traces instead of fprintf.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#2 lore raw
Quoted 18 lines · Eric Blake
Quoted 17 lines · Zhang Chen

Fix memory leak in colo-compare.c and filter-rewriter.c Report by Coverity.

---
  net/colo-compare.c    | 4 ++--
  net/filter-rewriter.c | 9 +++++----
  2 files changed, 7 insertions(+), 6 deletions(-)
net/colo-compare.c +0 -0
index 22b1da1..47e7ebe 100644
@@ -235,8 +235,8 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
          fprintf(stderr, "Secondary len = %d\n", spkt->size);
          qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
 
Quoted 8 lines

net/colo-compare.c static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) · line 239

Quoted 4 lines
net/colo-compare.c +2 -2
-        g_free(sdebug);
-        g_free(ddebug);
+        free(sdebug);
+        free(ddebug);

Uggh. We should fix the original allocations of sdebug and ddebug to use g_strdup_printf() rather than strdup(), so that we are using a consistent allocator throughout. Or even improve this code to use traces instead of fprintf.

OK~~ I get your point.
I will send patch V2 later.

Thanks
Zhang Chen

Quoted 1 line
Signature · 2 lines
Thanks
zhangchen