Commit 8cad55161c98b95deacdb9c1a66980f5b24d3179
Committed by
Anthony Liguori
1 parent
08b9d66b
net: add qemu_purge_queued_packets()
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 <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
2 changed files
with
17 additions
and
0 deletions
net.c
@@ -439,6 +439,22 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size) | @@ -439,6 +439,22 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size) | ||
439 | return ret; | 439 | return ret; |
440 | } | 440 | } |
441 | 441 | ||
442 | +void qemu_purge_queued_packets(VLANClientState *vc) | ||
443 | +{ | ||
444 | + VLANPacket **pp = &vc->vlan->send_queue; | ||
445 | + | ||
446 | + while (*pp != NULL) { | ||
447 | + VLANPacket *packet = *pp; | ||
448 | + | ||
449 | + if (packet->sender == vc) { | ||
450 | + *pp = packet->next; | ||
451 | + qemu_free(packet); | ||
452 | + } else { | ||
453 | + pp = &packet->next; | ||
454 | + } | ||
455 | + } | ||
456 | +} | ||
457 | + | ||
442 | void qemu_flush_queued_packets(VLANClientState *vc) | 458 | void qemu_flush_queued_packets(VLANClientState *vc) |
443 | { | 459 | { |
444 | VLANPacket *packet; | 460 | VLANPacket *packet; |
net.h
@@ -70,6 +70,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, | @@ -70,6 +70,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, | ||
70 | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); | 70 | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); |
71 | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, | 71 | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, |
72 | int size, NetPacketSent *sent_cb); | 72 | int size, NetPacketSent *sent_cb); |
73 | +void qemu_purge_queued_packets(VLANClientState *vc); | ||
73 | void qemu_flush_queued_packets(VLANClientState *vc); | 74 | void qemu_flush_queued_packets(VLANClientState *vc); |
74 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); | 75 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
75 | void qemu_check_nic_model(NICInfo *nd, const char *model); | 76 | void qemu_check_nic_model(NICInfo *nd, const char *model); |