[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] [PATCH] Fix some memory leak



Hi

This patch fixes some memory leak in libvirt.

1. The point that checks command-option in virsh.c
2. The point that checks version of Xen in xen_internal.c
3. The point that checks OS type of VM in xend_internal.c

And these memory leaks can be checked by valgrind.


Signed-off-by: Masayuki Sunou <fj1826dm aa jp fujitsu com>

Thanks,
Masayuki Sunou.

-------------------------------------------------------------------------------
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.76
diff -u -p -r1.76 virsh.c
--- src/virsh.c	23 May 2007 15:09:19 -0000	1.76
+++ src/virsh.c	29 May 2007 07:43:48 -0000
@@ -3153,8 +3153,10 @@ vshCommandParse(vshControl * ctl, char *
             c->def = cmd;
             c->next = NULL;
 
-            if (!vshCommandCheckOpts(ctl, c))
+            if (!vshCommandCheckOpts(ctl, c)) {
+                if(c) free(c);
                 goto syntaxError;
+            }
 
             if (!ctl->cmd)
                 ctl->cmd = c;
Index: src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.72
diff -u -p -r1.72 xen_internal.c
--- src/xen_internal.c	30 Apr 2007 17:30:11 -0000	1.72
+++ src/xen_internal.c	29 May 2007 07:43:48 -0000
@@ -1497,11 +1497,15 @@ xenHypervisorInit(void)
     virXenError(VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL);
     close(fd);
     in_init = 0;
+    if (ipt)
+        free(ipt);
     return(-1);
 
  done:
     close(fd);
     in_init = 0;
+    if (ipt)
+        free(ipt);
     return(0);
 }
 
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.114
diff -u -p -r1.114 xend_internal.c
--- src/xend_internal.c	11 May 2007 14:21:28 -0000	1.114
+++ src/xend_internal.c	29 May 2007 07:43:49 -0000
@@ -3072,7 +3072,7 @@ xenDaemonCreateLinux(virConnectPtr conn,
 static int
 xenDaemonAttachDevice(virDomainPtr domain, char *xml)
 {
-    char *sexpr, *conf;
+    char *sexpr, *conf, *str;
     int hvm = 0, ret;
     xenUnifiedPrivatePtr priv;
 
@@ -3084,8 +3084,11 @@ xenDaemonAttachDevice(virDomainPtr domai
 
     priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if (strcmp(virDomainGetOSType(domain), "linux"))
+    str = virDomainGetOSType(domain);
+    if (strcmp(str, "linux"))
         hvm = 1;
+    if (str)
+        free(str);
     sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
     if (sexpr == NULL)
         return (-1);
-------------------------------------------------------------------------------


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]