diff --git a/glnx-lockfile.c b/glnx-lockfile.c index 48f1ea75af0a964787b59c40b061e636e98e86a2..cd5c978c616546ccbe60db8cb49816b47b2725e9 100644 --- a/glnx-lockfile.c +++ b/glnx-lockfile.c @@ -126,21 +126,18 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc /* Note that if this is not AT_FDCWD, the caller takes responsibility * for the fd's lifetime being >= that of the lock. */ + out_lock->initialized = TRUE; out_lock->dfd = dfd; - out_lock->path = t; - out_lock->fd = fd; + out_lock->path = g_steal_pointer (&t); + out_lock->fd = glnx_steal_fd (&fd); out_lock->operation = operation; - - fd = -1; - t = NULL; - return TRUE; } void glnx_release_lock_file(GLnxLockFile *f) { int r; - if (!f) + if (!(f && f->initialized)) return; if (f->path) { @@ -181,4 +178,5 @@ void glnx_release_lock_file(GLnxLockFile *f) { (void) close (f->fd); f->fd = -1; f->operation = 0; + f->initialized = FALSE; } diff --git a/glnx-lockfile.h b/glnx-lockfile.h index 6d132e5fe38fe74a7f01dd6df0d0ff2aa73bb0dc..b346508942c829fc3f5d61a30d82c9dbc266bf6d 100644 --- a/glnx-lockfile.h +++ b/glnx-lockfile.h @@ -27,6 +27,7 @@ #include "glnx-backport-autoptr.h" typedef struct GLnxLockFile { + gboolean initialized; int dfd; char *path; int fd; @@ -37,5 +38,3 @@ gboolean glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile void glnx_release_lock_file(GLnxLockFile *f); G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxLockFile, glnx_release_lock_file) - -#define GLNX_LOCK_FILE_INIT { .fd = -1, .dfd = AT_FDCWD, .path = NULL }