diff mbox

[v3,4/4] ipmi_bmc_sim: Add a proper unrealize function

Message ID 1469217041-15358-5-git-send-email-minyard@acm.org
State New
Headers show

Commit Message

Corey Minyard July 22, 2016, 7:50 p.m. UTC
From: Corey Minyard <cminyard@mvista.com>


Add an unrealize function to free the timer allocated in the
realize function, unregister the vmstate, and free any
pending messages.

Signed-off-by: Corey Minyard <cminyard@mvista.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
 hw/ipmi/ipmi_bmc_sim.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index b742d8d..fe92b93 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -1780,12 +1780,28 @@  static void ipmi_sim_realize(DeviceState *dev, Error **errp)
     vmstate_register(NULL, 0, &vmstate_ipmi_sim, ibs);
 }
 
+static void ipmi_sim_unrealize(DeviceState *dev, Error **errp)
+{
+    IPMIBmc *b = IPMI_BMC(dev);
+    IPMIRcvBufEntry *msg, *tmp;
+    IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(b);
+
+    vmstate_unregister(NULL, &vmstate_ipmi_sim, ibs);
+    timer_del(ibs->timer);
+    timer_free(ibs->timer);
+    QTAILQ_FOREACH_SAFE(msg, &ibs->rcvbufs, entry, tmp) {
+        QTAILQ_REMOVE(&ibs->rcvbufs, msg, entry);
+        g_free(msg);
+    }
+}
+
 static void ipmi_sim_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
     IPMIBmcClass *bk = IPMI_BMC_CLASS(oc);
 
     dc->realize = ipmi_sim_realize;
+    dc->unrealize = ipmi_sim_unrealize;
     bk->handle_command = ipmi_sim_handle_command;
 }