[Libvirt-cim] [PATCH V2 02/48] Add others and unknown_device clean up

Xu Wang cngesaint at gmail.com
Mon Oct 28 02:45:31 UTC 2013


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/device_parsing.c |   54 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index aecca4c..f1da880 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -63,6 +63,49 @@
 /* Device parse function */
 typedef int (*dev_parse_func_t)(xmlNode *, struct virt_device **);
 
+void cleanup_node_of_others(struct others *others)
+{
+        if (others == NULL) {
+                return;
+        }
+
+        if (others->name) {
+                free(others->name);
+        }
+
+        if (others->parent_name) {
+                free(others->parent_name);
+        }
+
+        if (others->value) {
+                free(others->value);
+        }
+
+        free(others);
+}
+
+void cleanup_others(struct others *others)
+{
+        struct others *head = others;
+
+        if (others == NULL)
+                return;
+
+        while (head) {
+                head = others->next;
+                cleanup_node_of_others(others);
+                others = head;
+        }
+}
+
+static void cleanup_unknown_device(struct unknown_device *dev)
+{
+        if (dev == NULL)
+                return;
+
+        cleanup_others(dev->others);
+}
+
 static void cleanup_disk_device(struct disk_device *dev)
 {
         if (dev == NULL)
@@ -77,6 +120,7 @@ static void cleanup_disk_device(struct disk_device *dev)
         free(dev->virtual_dev);
         free(dev->bus_type);
         free(dev->access_mode);
+        cleanup_others(dev->others);
 }
 
 static void cleanup_vsi_device(struct vsi_device *dev)
@@ -107,6 +151,7 @@ static void cleanup_net_device(struct net_device *dev)
         free(dev->filter_ref);
         free(dev->poolid);
         cleanup_vsi_device(&dev->vsi);
+        cleanup_others(dev->others);
 }
 
 static void cleanup_emu_device(struct emu_device *dev)
@@ -115,6 +160,7 @@ static void cleanup_emu_device(struct emu_device *dev)
                 return;
 
         free(dev->path);
+        cleanup_others(dev->others);
 }
 
 static void cleanup_vnc_device(struct graphics_device *dev)
@@ -123,6 +169,7 @@ static void cleanup_vnc_device(struct graphics_device *dev)
         free(dev->dev.vnc.host);
         free(dev->dev.vnc.keymap);
         free(dev->dev.vnc.passwd);
+        cleanup_others(dev->dev.vnc.others);
 }
 
 static void cleanup_sdl_device(struct graphics_device *dev)
@@ -130,6 +177,7 @@ static void cleanup_sdl_device(struct graphics_device *dev)
         free(dev->dev.sdl.display);
         free(dev->dev.sdl.xauth);
         free(dev->dev.sdl.fullscreen);
+        cleanup_others(dev->dev.sdl.others);
 }
 
 static void cleanup_graphics_device(struct graphics_device *dev)
@@ -143,6 +191,7 @@ static void cleanup_graphics_device(struct graphics_device *dev)
                 cleanup_vnc_device(dev);
 
         free(dev->type);
+        cleanup_others(dev->others);
 }
 
 static void cleanup_path_device(struct path_device *dev)
@@ -228,6 +277,7 @@ static void cleanup_console_device(struct console_device *dev)
         dev->source_type = 0;
         free(dev->target_type);
         memset(&dev->source_dev, 0, sizeof(dev->source_dev));
+        cleanup_others(dev->others);
 };
 
 static void console_device_dup(struct console_device *t,
@@ -286,6 +336,7 @@ static void cleanup_input_device(struct input_device *dev)
 
         free(dev->type);
         free(dev->bus);
+        cleanup_others(dev->others);
 }
 
 void cleanup_virt_device(struct virt_device *dev)
@@ -305,6 +356,8 @@ void cleanup_virt_device(struct virt_device *dev)
                 cleanup_input_device(&dev->dev.input);
         else if (dev->type == CIM_RES_TYPE_CONSOLE)
                 cleanup_console_device(&dev->dev.console);
+        else if (dev->type == CIM_RES_TYPE_UNKNOWN)
+                cleanup_unknown_device(&dev->dev.unknown);
 
         free(dev->id);
 
@@ -1693,6 +1746,7 @@ void cleanup_dominfo(struct domain **dominfo)
         cleanup_virt_devices(&dom->dev_graphics, dom->dev_graphics_ct);
         cleanup_virt_devices(&dom->dev_input, dom->dev_input_ct);
         cleanup_virt_devices(&dom->dev_console, dom->dev_console_ct);
+        cleanup_virt_devices(&dom->dev_unknown, dom->dev_unknown_ct);
 
         free(dom);
 
-- 
1.7.1




More information about the Libvirt-cim mailing list