s3:g_lock: avoid useless talloc_array(0) in g_lock_dump()
authorStefan Metzmacher <metze@samba.org>
Thu, 18 Aug 2022 15:32:43 +0000 (17:32 +0200)
committerJule Anger <janger@samba.org>
Tue, 23 Aug 2022 07:46:18 +0000 (07:46 +0000)
In the common case we don't have any shared lock holders,
so there's no need to allocate memory for the empty array.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit c75de325710c0fbbd50a0acd3af55404165440d6)

source3/lib/g_lock.c

index 35279dddb76f2fbbda4e9b460fb0b11439b3954b..8a07949b3d92d71d067e2ec2925180c279964e53 100644 (file)
@@ -1238,12 +1238,14 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
                return;
        }
 
-       shared = talloc_array(
-               state->mem_ctx, struct server_id, lck.num_shared);
-       if (shared == NULL) {
-               DBG_DEBUG("talloc failed\n");
-               state->status = NT_STATUS_NO_MEMORY;
-               return;
+       if (lck.num_shared > 0) {
+               shared = talloc_array(
+                       state->mem_ctx, struct server_id, lck.num_shared);
+               if (shared == NULL) {
+                       DBG_DEBUG("talloc failed\n");
+                       state->status = NT_STATUS_NO_MEMORY;
+                       return;
+               }
        }
 
        for (i=0; i<lck.num_shared; i++) {