fs_lock:Check the nwaiter when deleting a bucket

Summary:
  Fixed the problem of releasing the bucket prematurely in multi-threaded flock scenarios.

A thread setlk
B thread setlk_wait
A thread releases lock but fails to determine if nwaiter causes the bucket to be released prematurely
post B thread causes crash due to heap use after free

https://github.com/apache/nuttx/issues/13821

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
chenrun1
2024-10-05 13:10:38 +08:00
committed by Xiang Xiao
parent f778660aca
commit 8f9857bf8c
+1 -1
View File
@@ -237,7 +237,7 @@ static void file_lock_delete_bucket(FAR struct file_lock_bucket_s *bucket,
* released
*/
if (list_is_empty(&bucket->list))
if (list_is_empty(&bucket->list) && bucket->nwaiter == 0)
{
/* At this point, the file has no lock information context, so we can
* remove it from the hash table, and the return result is 0 or 1 means