From: Stefan Metzmacher Date: Thu, 18 Aug 2022 15:32:43 +0000 (+0200) Subject: s3:g_lock: avoid useless talloc_array(0) in g_lock_dump() X-Git-Tag: talloc-2.4.0~1395 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c75de325710c0fbbd50a0acd3af55404165440d6;p=thirdparty%2Fsamba.git s3:g_lock: avoid useless talloc_array(0) in g_lock_dump() 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 35279dddb76..8a07949b3d9 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -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