Introduce VLANClientState::cleanup() (Mark McLoughlin)
We're currently leaking memory and file descriptors on device
hot-unplug.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7150 c046a42c-6fe2-441c-8c8c-71466251a162
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index 88c5620..a4c2011 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -69,6 +69,7 @@
VLANClientState *vc;
qemu_irq irq;
uint8_t macaddr[6];
+ int mmio_index;
} stellaris_enet_state;
static void stellaris_enet_update(stellaris_enet_state *s)
@@ -384,23 +385,35 @@
return 0;
}
+static void stellaris_enet_cleanup(VLANClientState *vc)
+{
+ stellaris_enet_state *s = vc->opaque;
+
+ unregister_savevm("stellaris_enet", s);
+
+ cpu_unregister_io_memory(s->mmio_index);
+
+ qemu_free(s);
+}
+
void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
{
stellaris_enet_state *s;
- int iomemtype;
qemu_check_nic_model(nd, "stellaris");
s = (stellaris_enet_state *)qemu_mallocz(sizeof(stellaris_enet_state));
- iomemtype = cpu_register_io_memory(0, stellaris_enet_readfn,
- stellaris_enet_writefn, s);
- cpu_register_physical_memory(base, 0x00001000, iomemtype);
+ s->mmio_index = cpu_register_io_memory(0, stellaris_enet_readfn,
+ stellaris_enet_writefn, s);
+ cpu_register_physical_memory(base, 0x00001000, s->mmio_index);
s->irq = irq;
memcpy(s->macaddr, nd->macaddr, 6);
if (nd->vlan) {
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
- stellaris_enet_receive, stellaris_enet_can_receive, s);
+ stellaris_enet_receive,
+ stellaris_enet_can_receive,
+ stellaris_enet_cleanup, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
}