r12221: Fix error code paths that can potentially leave a dangling lock.
authorJeremy Allison <jra@samba.org>
Wed, 14 Dec 2005 00:42:40 +0000 (00:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:05:49 +0000 (11:05 -0500)
Jeremy.
(This used to be commit 123135ed1ddd84cc0a5e8e5ca06a0703d1944e37)

source3/locking/locking.c

index d89fe931ef644c1fadff08a2a0aac6bb34ccb30a..b823b4712e73b388ce69be87832f43cc60773158 100644 (file)
@@ -595,12 +595,18 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
                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->dev = dev;
        lck->ino = ino;
-       lck->delete_on_close = False;
        lck->num_share_modes = 0;
        lck->share_modes = NULL;
        lck->num_share_modes = 0;
        lck->share_modes = NULL;
+       lck->delete_on_close = False;
        lck->modified = False;
        lck->modified = False;
+       lck->fresh = False;
 
        if (tdb_chainlock(tdb, key) != 0) {
                DEBUG(3, ("Could not lock share entry\n"));
 
        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;
        }
 
                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);
 
        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;
        SAFE_FREE(data.dptr);
 
        return lck;