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>
usleep(5000);
}
- if (lockfd) {
+ if (lockfd != -1) {
unlink(lockpath);
VIR_FORCE_CLOSE(lockfd);
VIR_FREE(lockpath);
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