From c528244f19a282eb4d3c4266fcbf93c3367fc1b3 Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Fri, 24 May 2024 16:12:16 +0800 Subject: [PATCH] fs_lock:Fixed the problem that in multi-threaded situations, the bucket may be deleted by other factors during the search process, resulting in assertion. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hsearch_r(item = (key = 0x61492174,data = ?),action = ?, retval = 0x6266AC44, htab = 0x6159B758) H 1tem = Ckey = 0x61492174, data= : · action = ? retval = 0x6266AC44 htab = 0x6159B758 haad - 0x61616300 ie= 0×38 file_lock_find_bucket(inline) filepath = 0x61492174 hretvalue = 0x6055991D item = (key = 0x61492174, data = 0x0) Signed-off-by: chenrun1 --- fs/vfs/fs_lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_lock.c b/fs/vfs/fs_lock.c index 82a5ec1e46..bfb430577b 100644 --- a/fs/vfs/fs_lock.c +++ b/fs/vfs/fs_lock.c @@ -767,15 +767,16 @@ void file_closelk(FAR struct file *filep) goto out; } + nxmutex_lock(&g_protect_lock); bucket = file_lock_find_bucket(path); if (bucket == NULL) { /* There is no bucket here, so we don't need to free it. */ + nxmutex_unlock(&g_protect_lock); goto out; } - nxmutex_lock(&g_protect_lock); list_for_every_entry_safe(&bucket->list, file_lock, temp, struct file_lock_s, fl_node) {