diff mbox

colo-proxy: fix memory leak

Message ID 1476092814-5199-1-git-send-email-zhangchen.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhang Chen Oct. 10, 2016, 9:46 a.m. UTC
Fix memory leak in colo-compare.c and filter-rewriter.c
Report by Coverity.

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
---
 net/colo-compare.c    | 4 ++--
 net/filter-rewriter.c | 9 +++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

Comments

Eric Blake Oct. 10, 2016, 8:23 p.m. UTC | #1
On 10/10/2016 04:46 AM, Zhang Chen wrote:
> Fix memory leak in colo-compare.c and filter-rewriter.c
> Report by Coverity.
> 
> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
> ---
>  net/colo-compare.c    | 4 ++--
>  net/filter-rewriter.c | 9 +++++----
>  2 files changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index 22b1da1..47e7ebe 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -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.
Zhang Chen Oct. 11, 2016, 3:37 a.m. UTC | #2
On 10/11/2016 04:23 AM, Eric Blake wrote:
> On 10/10/2016 04:46 AM, Zhang Chen wrote:
>> Fix memory leak in colo-compare.c and filter-rewriter.c
>> Report by Coverity.
>>
>> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
>> ---
>>   net/colo-compare.c    | 4 ++--
>>   net/filter-rewriter.c | 9 +++++----
>>   2 files changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/net/colo-compare.c b/net/colo-compare.c
>> index 22b1da1..47e7ebe 100644
>> --- a/net/colo-compare.c
>> +++ b/net/colo-compare.c
>> @@ -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.

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

Thanks
Zhang Chen


>
diff mbox

Patch

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 22b1da1..47e7ebe 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -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;
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index 89abe72..396a03c 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -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