
On 07/29/2011 04:05 AM, Wayne Xia wrote: [snip]
diff -r 0f42cab9c45c -r 640ea61807cf libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Mon Jul 25 13:14:22 2011 -0700 +++ b/libxkutil/device_parsing.c Mon Jul 25 19:39:08 2011 +0800 @@ -88,13 +88,31 @@ free(dev->path); }
+static void cleanup_vnc_device(struct graphics_device *dev) +{ + free(dev->type); + free(dev->dev.vnc.port); + free(dev->dev.vnc.host); + free(dev->dev.vnc.keymap); + free(dev->dev.vnc.passwd); +} + +static void cleanup_sdl_device(struct graphics_device *dev) +{ + free(dev->type); + free(dev->dev.sdl.display); + free(dev->dev.sdl.xauth); + free(dev->dev.sdl.fullscreen); +} + static void cleanup_graphics_device(struct graphics_device *dev) { - free(dev->type); - free(dev->port); - free(dev->host); - free(dev->keymap); - free(dev->passwd); + if (STREQC(dev->type, "sdl")) { + cleanup_sdl_device(dev); + } + else { + cleanup_vnc_device(dev); + } }
As dev->type is a common field, it should be on the cleanup_graphics function, while the cleanup_sdl and cleanup_vnc would handle the specifics thus avoiding code duplicity.
diff -r 0f42cab9c45c -r 640ea61807cf libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Mon Jul 25 13:14:22 2011 -0700 +++ b/libxkutil/device_parsing.h Mon Jul 25 19:39:08 2011 +0800 @@ -84,14 +84,28 @@ char *path; };
-struct graphics_device { - char *type; +//vnc_device must be larger or equal than sdl_device
With the specific cleanup functions this comment is not necessary. ACK, I think those small bits can be fixed before pushing. -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima@br.ibm.com