diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-17 17:11:08 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-17 17:11:08 +0000 |
commit | b946a1533209f61a93e34898aebb5b43154b99c3 (patch) | |
tree | 36b0017910ca42cc5a41671b8edc7faa5da0a452 /hw/stellaris_enet.c | |
parent | 32a8f6ae93f175518f86f99249177c35d1a85114 (diff) |
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
Diffstat (limited to 'hw/stellaris_enet.c')
-rw-r--r-- | hw/stellaris_enet.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c index 88c56204e3..a4c2011113 100644 --- a/hw/stellaris_enet.c +++ b/hw/stellaris_enet.c @@ -69,6 +69,7 @@ typedef struct { 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 @@ static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id) 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); } |