From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEE9G-0001h9-Vg for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:01:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEE9B-00039t-9i for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:01:42 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:36114 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEE9B-00039i-3K for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:01:37 -0400 References: <1407140744-11948-1-git-send-email-zhang.zhanghailiang@huawei.com> <1407140744-11948-3-git-send-email-zhang.zhanghailiang@huawei.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= Date: Mon, 04 Aug 2014 10:01:09 +0100 In-reply-to: <1407140744-11948-3-git-send-email-zhang.zhanghailiang@huawei.com> Message-ID: <87fvhcvdam.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 2/4] monitor: fix access freed memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: zhanghailiang Cc: kwolf@redhat.com, alex@alex.org.uk, mst@redhat.com, luonengjun@huawei.com, peter.huangpeng@huawei.com, qemu-devel@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com zhanghailiang writes: > The function monitor_fdset_dup_fd_find_remove() references member of 'mon_fdset' > which may be freed in function monitor_fdset_cleanup() > > Signed-off-by: zhanghailiang > --- > monitor.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/monitor.c b/monitor.c > index 5bc70a6..41e46a6 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -2532,8 +2532,10 @@ static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove) > { > MonFdset *mon_fdset; > MonFdsetFd *mon_fdset_fd_dup; > + int64_t id = -1; > > QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { > + id = mon_fdset->id; > QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) { > if (mon_fdset_fd_dup->fd == dup_fd) { > if (remove) { > @@ -2542,7 +2544,7 @@ static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove) > monitor_fdset_cleanup(mon_fdset); > } > } > - return mon_fdset->id; > + return id; > } > } > } If monitor_fdset_cleanup closes the FD won't you now be passing an invalid fd to the calling function? -- Alex Bennée