From ce30f80d2ca7bd588f5f52f69b5b6240a25f6d06 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Sat, 28 Sep 2024 11:10:42 +0200 Subject: [PATCH] [client,common] disable clang-tidy for function change_lock moves ownership of allocated CliprdrLocalStream to file->local_streams. Do not complain about possible memory leak (false positive) --- client/common/client_cliprdr_file.c | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/client/common/client_cliprdr_file.c b/client/common/client_cliprdr_file.c index 2f20327e0..d4078d23d 100644 --- a/client/common/client_cliprdr_file.c +++ b/client/common/client_cliprdr_file.c @@ -1491,29 +1491,34 @@ static UINT change_lock(CliprdrFileContext* file, UINT32 lockId, BOOL lock) WINPR_ASSERT(file); HashTable_Lock(file->local_streams); - CliprdrLocalStream* stream = HashTable_GetItemValue(file->local_streams, &lockId); - if (lock && !stream) + { - stream = cliprdr_local_stream_new(file, lockId, NULL, 0); - if (!HashTable_Insert(file->local_streams, &lockId, stream)) + CliprdrLocalStream* stream = HashTable_GetItemValue(file->local_streams, &lockId); + if (lock && !stream) { - rc = ERROR_INTERNAL_ERROR; - cliprdr_local_stream_free(stream); - stream = NULL; + stream = cliprdr_local_stream_new(file, lockId, NULL, 0); + if (!HashTable_Insert(file->local_streams, &lockId, stream)) + { + rc = ERROR_INTERNAL_ERROR; + cliprdr_local_stream_free(stream); + stream = NULL; + } + file->local_lock_id = lockId; + } + if (stream) + { + stream->locked = lock; + stream->lockId = lockId; } - file->local_lock_id = lockId; - } - if (stream) - { - stream->locked = lock; - stream->lockId = lockId; } + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): HashTable_Insert ownership stream if (!lock) { if (!HashTable_Foreach(file->local_streams, local_stream_discard, file)) rc = ERROR_INTERNAL_ERROR; } + HashTable_Unlock(file->local_streams); return rc; }