From: Hailiang Zhang <zhang.zhanghailiang@huawei.com>
To: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>,
jasowang@redhat.com, lizhijian@cn.fujitsu.com
Cc: xuquan8@huawei.com, qemu-devel@nongnu.org, pss.wulizhen@huawei.com
Subject: Re: [Qemu-devel] [PATCH 1/3] net/colo: fix memory double free error
Date: Tue, 21 Feb 2017 11:06:29 +0800 [thread overview]
Message-ID: <58ABAEB5.7000704@huawei.com> (raw)
In-Reply-To: <d3be835a-fd51-8ca5-27f9-e29fc63c1c98@cn.fujitsu.com>
On 2017/2/21 10:25, Zhang Chen wrote:
>
>
> 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.
>
Ha, you are right, my original modification will introduce memory leak.
Will fix in next version.
> 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);
>> }
>>
>
next prev parent reply other threads:[~2017-02-21 3:07 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
2017-02-21 3:06 ` Hailiang Zhang [this message]
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=58ABAEB5.7000704@huawei.com \
--to=zhang.zhanghailiang@huawei.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=zhangchen.fnst@cn.fujitsu.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.