From 762901cfb9aabb717b8312d546ab20f8bacb1e29 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Dec 2005 00:42:40 +0000 Subject: r12221: Fix error code paths that can potentially leave a dangling lock. Jeremy. (This used to be commit 123135ed1ddd84cc0a5e8e5ca06a0703d1944e37) --- source3/locking/locking.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source3/locking') diff --git a/source3/locking/locking.c b/source3/locking/locking.c index d89fe931ef..b823b4712e 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -595,12 +595,18 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, return NULL; } + /* Ensure we set every field here as the destructor must be + valid even if parse_share_modes fails. */ + + lck->servicepath = NULL; + lck->filename = NULL; lck->dev = dev; lck->ino = ino; - lck->delete_on_close = False; lck->num_share_modes = 0; lck->share_modes = NULL; + lck->delete_on_close = False; lck->modified = False; + lck->fresh = False; if (tdb_chainlock(tdb, key) != 0) { DEBUG(3, ("Could not lock share entry\n")); @@ -608,6 +614,12 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, return NULL; } + /* We must set the destructor immediately after the chainlock + ensure the lock is cleaned up on any of the error return + paths below. */ + + talloc_set_destructor(lck, share_mode_lock_destructor); + data = tdb_fetch(tdb, key); lck->fresh = (data.dptr == NULL); @@ -634,7 +646,6 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, } } - talloc_set_destructor(lck, share_mode_lock_destructor); SAFE_FREE(data.dptr); return lck; -- cgit