colo-proxy: fix memory leak
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
@@ -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
@@ -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
Quoted 14 lines · Zhang Chen
Fix memory leak in
colo-compare.candfilter-rewriter.cReport by Coverity.Signed-off-by Zhang Chen <[email protected]>--- net/colo-compare.c | 4 ++-- net/filter-rewriter.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-)net/colo-compare.c +0
-0
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
Quoted 18 lines · Eric Blake
Quoted 17 lines · Zhang Chen
Fix memory leak in
colo-compare.candfilter-rewriter.cReport by Coverity.Signed-off-by Zhang Chen <[email protected]>--- net/colo-compare.c | 4 ++-- net/filter-rewriter.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-)net/colo-compare.c +0
-0@@ -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 thanstrdup(), 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