From 54ec89d950850c3c45e0daf9e86056091eff1ae0 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 25 Jun 2023 11:04:53 +0300 Subject: [PATCH] (unlock_file): eliminate goto, reduce variable scopes. Signed-off-by: Andrew Borodin --- lib/lock.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/lock.c b/lib/lock.c index b6edc6fb4..bae709311 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -279,8 +279,7 @@ int unlock_file (const vfs_path_t * fname_vpath) { char *lockfname; - struct stat statbuf; - const char *elpath, *lock; + const char *elpath; if (fname_vpath == NULL) return 0; @@ -291,27 +290,24 @@ unlock_file (const vfs_path_t * fname_vpath) return 0; lockfname = lock_build_symlink_name (fname_vpath); - - if (lockfname == NULL) - return 0; - - /* Check if lock exists */ - if (lstat (lockfname, &statbuf) == -1) - goto ret; - - lock = lock_get_info (lockfname); - if (lock != NULL) + if (lockfname != NULL) { - /* Don't touch if lock is not ours */ - if (lock_extract_info (lock)->pid != getpid ()) - goto ret; + struct stat statbuf; + + /* Check if lock exists */ + if (lstat (lockfname, &statbuf) != -1) + { + const char *lock; + + lock = lock_get_info (lockfname); + /* Don't touch if lock is not ours */ + if (lock == NULL || lock_extract_info (lock)->pid == getpid ()) + unlink (lockfname); + } + + g_free (lockfname); } - /* Remove lock */ - unlink (lockfname); - - ret: - g_free (lockfname); return 0; }