diff options
author | Jeremy Allison <jra@samba.org> | 2005-12-14 00:42:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:05:49 -0500 |
commit | 123135ed1ddd84cc0a5e8e5ca06a0703d1944e37 (patch) | |
tree | 5c1314e9e48a212f105660f1d00f857f5b912110 /source | |
parent | 7c545e1e77c3e235b21eb11d5ced91c603da491d (diff) | |
download | samba-123135ed1ddd84cc0a5e8e5ca06a0703d1944e37.tar.gz samba-123135ed1ddd84cc0a5e8e5ca06a0703d1944e37.tar.xz samba-123135ed1ddd84cc0a5e8e5ca06a0703d1944e37.zip |
r12221: Fix error code paths that can potentially leave a dangling lock.
Jeremy.
Diffstat (limited to 'source')
-rw-r--r-- | source/locking/locking.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/source/locking/locking.c b/source/locking/locking.c index d89fe931ef6..b823b4712e7 100644 --- a/source/locking/locking.c +++ b/source/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; |