From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MHLJ4-0006Xg-6D for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MHLIz-0006RG-6P for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:45 -0400 Received: from [199.232.76.173] (port=43811 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MHLIy-0006Qy-VS for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:41 -0400 Received: from mail23.svc.cra.dublin.eircom.net ([159.134.118.145]:32252) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MHLIy-0008Se-It for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:40 -0400 From: Mark McLoughlin Date: Thu, 18 Jun 2009 18:21:29 +0100 Message-Id: <1245345696-20915-2-git-send-email-markmc@redhat.com> In-Reply-To: <1245345696-20915-1-git-send-email-markmc@redhat.com> References: <1245345696-20915-1-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 1/8] net: add qemu_purge_queued_packets() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mark McLoughlin If net client sends packets asynchronously, it needs to purge its queued packets in cleanup() so as to prevent sent callbacks being invoked with a freed client. Signed-off-by: Mark McLoughlin --- net.c | 16 ++++++++++++++++ net.h | 1 + 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/net.c b/net.c index 9f9e363..0753a7c 100644 --- a/net.c +++ b/net.c @@ -439,6 +439,22 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size) return ret; } +void qemu_purge_queued_packets(VLANClientState *vc) +{ + VLANPacket **pp = &vc->vlan->send_queue; + + while (*pp != NULL) { + VLANPacket *packet = *pp; + + if (packet->sender == vc) { + *pp = packet->next; + qemu_free(packet); + } else { + pp = &packet->next; + } + } +} + void qemu_flush_queued_packets(VLANClientState *vc) { VLANPacket *packet; diff --git a/net.h b/net.h index a9abf63..ef85087 100644 --- a/net.h +++ b/net.h @@ -70,6 +70,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, int size, NetPacketSent *sent_cb); +void qemu_purge_queued_packets(VLANClientState *vc); void qemu_flush_queued_packets(VLANClientState *vc); void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); void qemu_check_nic_model(NICInfo *nd, const char *model); -- 1.6.0.6