]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
rpc_server: Only allocate fsp when counting file locks
authorShwetha Acharya <Shwetha.K.Acharya@ibm.com>
Thu, 5 Mar 2026 12:01:52 +0000 (17:31 +0530)
committerAnoop C S <anoopcs@samba.org>
Tue, 14 Apr 2026 10:02:29 +0000 (10:02 +0000)
Avoids creating fsp, which is not needed unless we
are going to count the brlocks.

Also uses early continue and removes num_locks variable
by assigning the result directly.

Signed-off-by: Shwetha Acharya <Shwetha.K.Acharya@ibm.com>
Reviewed-by: Xavi Hernandez <xhernandez@redhat.com>
Reviewed-by: Shweta Sodani <ssodani@redhat.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Tue Apr 14 10:02:29 UTC 2026 on atb-devel-224

source3/rpc_server/srvsvc/srv_srvsvc_nt.c

index 5a03daf5f0de7bebd303920231e4175e00573771..556113faf18c42144bfee56d6bfc480bf1043348 100644 (file)
@@ -196,7 +196,12 @@ static WERROR net_enum_files(TALLOC_CTX *ctx,
        for (i=0; i<(*ctr3)->count; i++) {
                struct files_struct *fsp = NULL;
                struct byte_range_lock *brl = NULL;
-               unsigned int num_locks = 0;
+
+               (*ctr3)->array[i].num_locks = 0;
+
+               if (!count_file_locks) {
+                       continue;
+               }
 
                fsp = talloc_zero(talloc_tos(), struct files_struct);
                if (fsp == NULL) {
@@ -204,16 +209,11 @@ static WERROR net_enum_files(TALLOC_CTX *ctx,
                }
                fsp->file_id = f_enum_cnt.fids[i];
 
-               if (count_file_locks) {
-                       brl = brl_get_locks_readonly(fsp);
-                       if (brl != NULL) {
-                               num_locks = brl_num_locks(brl);
-                               TALLOC_FREE(brl);
-                       }
+               brl = brl_get_locks_readonly(fsp);
+               if (brl != NULL) {
+                       (*ctr3)->array[i].num_locks = brl_num_locks(brl);
+                       TALLOC_FREE(brl);
                }
-
-               (*ctr3)->array[i].num_locks = num_locks;
-
                TALLOC_FREE(fsp);
        }