From patchwork Tue Oct 11 07:33:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 680630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3stTMB4w1hz9sC7 for ; Tue, 11 Oct 2016 18:36:22 +1100 (AEDT) Received: from localhost ([::1]:54163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrbn-00020L-NG for incoming@patchwork.ozlabs.org; Tue, 11 Oct 2016 03:36:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrZ9-0000lX-VO for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:33:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btrZ4-00031e-Vs for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:33:34 -0400 Received: from [59.151.112.132] (port=50643 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrZ3-0002z0-Rr for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:33:30 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="11818629" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Oct 2016 15:33:22 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 54282403C874; Tue, 11 Oct 2016 15:33:18 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Tue, 11 Oct 2016 15:33:16 +0800 From: Zhang Chen To: qemu devel , Jason Wang , Zhang Chen , Eric Blake Date: Tue, 11 Oct 2016 15:33:27 +0800 Message-ID: <1476171207-18472-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 54282403C874.AA299 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V2] colo-proxy: fix memory leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Li Zhijian Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Fix memory leak in colo-compare.c and filter-rewriter.c Report by Coverity. v2: - use traces instead of fprintf in colo-compare.c v1: - initial patch Signed-off-by: Zhang Chen --- net/colo-compare.c | 11 +++-------- net/filter-rewriter.c | 17 +++++------------ trace-events | 1 + 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 22b1da1..bbb6ca6 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -188,7 +188,6 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) { struct tcphdr *ptcp, *stcp; int res; - char *sdebug, *ddebug; trace_colo_compare_main("compare tcp"); if (ppkt->size != spkt->size) { @@ -219,11 +218,9 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) (spkt->size - ETH_HLEN)); if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { - sdebug = strdup(inet_ntoa(ppkt->ip->ip_src)); - ddebug = strdup(inet_ntoa(ppkt->ip->ip_dst)); - fprintf(stderr, "%s: src/dst: %s/%s p: seq/ack=%u/%u" - " s: seq/ack=%u/%u res=%d flags=%x/%x\n", - __func__, sdebug, ddebug, + trace_colo_compare_pkt_info(__func__, + inet_ntoa(ppkt->ip->ip_src), + inet_ntoa(ppkt->ip->ip_dst), (unsigned int)ntohl(ptcp->th_seq), (unsigned int)ntohl(ptcp->th_ack), (unsigned int)ntohl(stcp->th_seq), @@ -235,8 +232,6 @@ 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); } return res; diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index 89abe72..c4ab91c 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -68,15 +68,11 @@ static int handle_primary_tcp_pkt(NetFilterState *nf, tcp_pkt = (struct tcphdr *)pkt->transport_header; if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) { - char *sdebug, *ddebug; - sdebug = strdup(inet_ntoa(pkt->ip->ip_src)); - ddebug = strdup(inet_ntoa(pkt->ip->ip_dst)); - trace_colo_filter_rewriter_pkt_info(__func__, sdebug, ddebug, + trace_colo_filter_rewriter_pkt_info(__func__, + inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst), 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); } if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) { @@ -116,15 +112,11 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf, tcp_pkt = (struct tcphdr *)pkt->transport_header; if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) { - char *sdebug, *ddebug; - sdebug = strdup(inet_ntoa(pkt->ip->ip_src)); - ddebug = strdup(inet_ntoa(pkt->ip->ip_dst)); - trace_colo_filter_rewriter_pkt_info(__func__, sdebug, ddebug, + trace_colo_filter_rewriter_pkt_info(__func__, + inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst), 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); } if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) { @@ -162,6 +154,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 diff --git a/trace-events b/trace-events index 1cb9d37..8115430 100644 --- a/trace-events +++ b/trace-events @@ -149,6 +149,7 @@ colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s" colo_old_packet_check_found(int64_t old_time) "%" PRId64 colo_compare_miscompare(void) "" +colo_compare_pkt_info(const char *func, const char *src, const char *dst, uint32_t pseq, uint32_t pack, uint32_t sseq, uint32_t sack, int res, uint32_t pflag, uint32_t sflag) "%s: src/dst: %s/%s p: seq/ack=%u/%u s: seq/ack=%u/%u res=%d flags=%x/%x\n" # net/filter-rewriter.c colo_filter_rewriter_debug(void) ""