]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virNetSocketNewConnectUNIX: Don't unlink(NULL)
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 16 Apr 2015 14:07:15 +0000 (16:07 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 17 Apr 2015 08:02:28 +0000 (10:02 +0200)
There is a possibility that we jump onto error label with @lockpath
still initialized to NULL. Here, the @lockpath should be unlink()-ed,
but passing there a NULL is not a good idea. Don't do that. In fact,
we should call unlink() only if we created the lock file successfully.

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/rpc/virnetsocket.c

index b8242850ae8c01e8a994ee1a4fa2994d96707e36..a59e3e11542beea53ed2e5f1b1140588a273ae07 100644 (file)
@@ -622,7 +622,7 @@ int virNetSocketNewConnectUNIX(const char *path,
         usleep(5000);
     }
 
-    if (lockfd) {
+    if (lockfd != -1) {
         unlink(lockpath);
         VIR_FORCE_CLOSE(lockfd);
         VIR_FREE(lockpath);
@@ -640,12 +640,13 @@ int virNetSocketNewConnectUNIX(const char *path,
     return 0;
 
  error:
-    if (lockfd)
+    if (lockfd != -1) {
         unlink(lockpath);
+        VIR_FORCE_CLOSE(lockfd);
+    }
     VIR_FREE(lockpath);
     VIR_FREE(rundir);
     VIR_FORCE_CLOSE(fd);
-    VIR_FORCE_CLOSE(lockfd);
     return -1;
 }
 #else