]> xenbits.xensource.com Git - libvirt.git/commitdiff
Avoid segfault upon malloc failure, and plug a leak.
authorJim Meyering <meyering@redhat.com>
Wed, 30 Jan 2008 19:52:16 +0000 (19:52 +0000)
committerJim Meyering <meyering@redhat.com>
Wed, 30 Jan 2008 19:52:16 +0000 (19:52 +0000)
* src/test.c (testDomainSave): Detect testDomainDumpXML failure.  Free "xml".

ChangeLog
src/test.c

index fad8577f114ce69e2ae10eba0ed8c32c83003804..8b26a4b8dad236fe6ff822bba6c602bb071aced4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 Wed Jan 30 20:49:34 CET 2008  Jim Meyering  <meyering@redhat.com>
 
+       Avoid segfault upon malloc failure, and plug a leak.
+       * src/test.c (testDomainSave): Detect testDomainDumpXML failure.
+       Free "xml".
+
        Plug test-related leaks.
        * src/test.c (testLoadNetwork): Free forwardDev.
        (testLoadDomain): Free ctxt.
index 35e41a3dce3dc7daa13f436f7879cda91c1f5b5b..85170d9961319cfdfa7245904a5b108d7a77f650 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test.c: A "mock" hypervisor for use by application unit tests
  *
- * Copyright (C) 2006-2007 Red Hat, Inc.
+ * Copyright (C) 2006-2008 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -1281,6 +1281,11 @@ static int testDomainSave(virDomainPtr domain,
     GET_DOMAIN(domain, -1);
 
     xml = testDomainDumpXML(domain, 0);
+    if (xml == NULL) {
+        testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
+                  "cannot allocate space for metadata");
+        return (-1);
+    }
 
     if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
         testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1303,9 +1308,11 @@ static int testDomainSave(virDomainPtr domain,
     if (write(fd, xml, len) != len) {
         testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
                   "cannot write metadata");
+        free(xml);
         close(fd);
         return (-1);
     }
+    free(xml);
     if (close(fd) < 0) {
         testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
                   "cannot save domain data");