All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>,
	jasowang@redhat.com, lizhijian@cn.fujitsu.com
Cc: qemu-devel@nongnu.org, xuquan8@huawei.com, pss.wulizhen@huawei.com
Subject: Re: [Qemu-devel] [PATCH 1/3] net/colo: fix memory double free error
Date: Tue, 21 Feb 2017 10:25:13 +0800	[thread overview]
Message-ID: <d3be835a-fd51-8ca5-27f9-e29fc63c1c98@cn.fujitsu.com> (raw)
In-Reply-To: <1487577721-31084-2-git-send-email-zhang.zhanghailiang@huawei.com>



On 02/20/2017 04:01 PM, zhanghailiang wrote:
> The 'primary_list' and 'secondary_list' members of struct Connection
> is not allocated through dynamically g_queue_new(), but we free it by using
> g_queue_free(), which will lead to a double-free bug.
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>   net/colo.c | 2 --
>   1 file changed, 2 deletions(-)
>
> diff --git a/net/colo.c b/net/colo.c
> index 6a6eacd..7d5c423 100644
> --- a/net/colo.c
> +++ b/net/colo.c
> @@ -147,9 +147,7 @@ void connection_destroy(void *opaque)
>       Connection *conn = opaque;
>   
>       g_queue_foreach(&conn->primary_list, packet_destroy, NULL);
> -    g_queue_free(&conn->primary_list);
>       g_queue_foreach(&conn->secondary_list, packet_destroy, NULL);
> -    g_queue_free(&conn->secondary_list);

I think we need use g_queue_clear () here.

void
g_queue_clear (GQueue *queue);
Removes all the elements in queue . If queue elements contain 
dynamically-allocated memory, they should be freed first.

Thanks
Zhang Chen

>       g_slice_free(Connection, conn);
>   }
>   

-- 
Thanks
Zhang Chen

  reply	other threads:[~2017-02-21  2:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20  8:01 [Qemu-devel] [PATCH 0/3] filter-rewriter: fix two bugs and one optimization zhanghailiang
2017-02-20  8:01 ` [Qemu-devel] [PATCH 1/3] net/colo: fix memory double free error zhanghailiang
2017-02-21  2:25   ` Zhang Chen [this message]
2017-02-21  3:06     ` Hailiang Zhang
2017-02-20  8:02 ` [Qemu-devel] [PATCH 2/3] filter-rewriter: fix memory leak for connection in connection_track_table zhanghailiang
2017-02-20  8:02 ` [Qemu-devel] [PATCH 3/3] filter-rewriter: skip net_checksum_calculate() while offset = 0 zhanghailiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d3be835a-fd51-8ca5-27f9-e29fc63c1c98@cn.fujitsu.com \
    --to=zhangchen.fnst@cn.fujitsu.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=pss.wulizhen@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xuquan8@huawei.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.