[PATCH] virNetSocketNewConnectUNIX: Don't unlink(NULL)

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

 



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@xxxxxxxxxx>
Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/rpc/virnetsocket.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index b824285..a59e3e1 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -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
-- 
2.0.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]