]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: fix releasing pidfile in cleanup
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 4 Nov 2014 09:46:41 +0000 (10:46 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 4 Nov 2014 11:06:38 +0000 (12:06 +0100)
Coverity found out the very obvious problem in the code.  That is that
virPidFileReleasePath() was called only if
virPidFileAcquirePath() returned 0.  But virPidFileAcquirePath() doesn't
return only 0 on success, but the FD that needs to be closed.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/util/virpidfile.c

index 098458f7eb2e75e3245f6dcabfb8a52e60134afb..a77a326506f7e3ae9146a6ab37bbb010b5acc6be 100644 (file)
@@ -592,9 +592,8 @@ virPidFileForceCleanupPath(const char *path)
     if (virPidFileReadPath(path, &pid) < 0)
         return -1;
 
-    if (virPidFileAcquirePath(path, false, 0) == 0) {
-        virPidFileReleasePath(path, fd);
-    } else {
+    fd = virPidFileAcquirePath(path, false, 0);
+    if (fd < 0) {
         virResetLastError();
 
         /* Only kill the process if the pid is valid one.  0 means
@@ -607,5 +606,8 @@ virPidFileForceCleanupPath(const char *path)
             return -1;
     }
 
+    if (fd)
+        virPidFileReleasePath(path, fd);
+
     return 0;
 }