smbd: Simplify get_share_mode_lock a bit
authorVolker Lendecke <vl@samba.org>
Fri, 6 Dec 2013 07:40:03 +0000 (07:40 +0000)
committerStefan Metzmacher <metze@samba.org>
Sat, 14 Dec 2013 09:08:56 +0000 (10:08 +0100)
This does two things: It gets rid of a talloc_stackframe in a hot
code path and to me it makes the code easier to understand. It makes
the talloc hierarchy more obvious to follow.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/locking/share_mode_lock.c

index 5d7a08ca4bf018232aba3a6f41dcc08967afd0f1..940d1253f47c219956bafe391be576dd2ae3f8c6 100644 (file)
@@ -369,36 +369,35 @@ struct share_mode_lock *get_share_mode_lock(
        const struct smb_filename *smb_fname,
        const struct timespec *old_write_time)
 {
-       TALLOC_CTX *frame = talloc_stackframe();
-
        struct share_mode_lock *lck;
 
+       lck = talloc(mem_ctx, struct share_mode_lock);
+       if (lck == NULL) {
+               DEBUG(1, ("talloc failed\n"));
+               return NULL;
+       }
+
        if (the_lock == NULL) {
                the_lock = get_share_mode_lock_internal(
-                       frame, id, servicepath, smb_fname, old_write_time);
+                       lck, id, servicepath, smb_fname, old_write_time);
                if (the_lock == NULL) {
                        goto fail;
                }
                talloc_set_destructor(the_lock, the_lock_destructor);
+       } else {
+               if (talloc_reference(lck, the_lock) == NULL) {
+                       DEBUG(1, ("talloc_reference failed\n"));
+                       goto fail;
+               }
        }
        if (!file_id_equal(&the_lock->data->id, &id)) {
                DEBUG(1, ("Can not lock two share modes simultaneously\n"));
                goto fail;
        }
-       lck = talloc(mem_ctx, struct share_mode_lock);
-       if (lck == NULL) {
-               DEBUG(1, ("talloc failed\n"));
-               goto fail;
-       }
-       if (talloc_reference(lck, the_lock) == NULL) {
-               DEBUG(1, ("talloc_reference failed\n"));
-               goto fail;
-       }
        lck->data = the_lock->data;
-       TALLOC_FREE(frame);
        return lck;
 fail:
-       TALLOC_FREE(frame);
+       TALLOC_FREE(lck);
        return NULL;
 }