]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: avoid null pointer dereference
authorEric Blake <eblake@redhat.com>
Tue, 3 May 2011 16:37:13 +0000 (10:37 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 3 May 2011 16:50:56 +0000 (10:50 -0600)
Unlikely to hit in real life, but clang noticed it.

* tests/commandtest.c (checkoutput, test4, test18): Avoid
unlink(NULL) on OOM.

tests/commandtest.c

index fa0061cba1fc0335ee38f38126fd5a28ab9cf5c7..caad69832af339d6dfbef49fc094d0688ca1ecca 100644 (file)
@@ -78,7 +78,8 @@ static int checkoutput(const char *testname)
     ret = 0;
 
 cleanup:
-    unlink(actualname);
+    if (actualname)
+        unlink(actualname);
     VIR_FREE(actuallog);
     VIR_FREE(actualname);
     VIR_FREE(expectlog);
@@ -240,7 +241,8 @@ static int test4(const void *unused ATTRIBUTE_UNUSED)
 
 cleanup:
     virCommandFree(cmd);
-    unlink(pidfile);
+    if (pidfile)
+        unlink(pidfile);
     VIR_FREE(pidfile);
     return ret;
 }
@@ -703,7 +705,8 @@ static int test18(const void *unused ATTRIBUTE_UNUSED)
 
 cleanup:
     virCommandFree(cmd);
-    unlink(pidfile);
+    if (pidfile)
+        unlink(pidfile);
     VIR_FREE(pidfile);
     return ret;
 }