This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b6733c0564 fs/mqueue: fix inverted 'created' flag in file_mq_vopen
1b6733c0564 is described below

commit 1b6733c0564729348fb55e0359a17c5fedde08da
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Tue Jul 1 18:44:11 2025 +0800

    fs/mqueue: fix inverted 'created' flag in file_mq_vopen
    
    The 'created' flag values were incorrectly inverted in file_mq_vopen():
    
    1. When opening an existing message queue (inode_find succeeds):
       - Before: incorrectly set *created = 1 (indicating new creation)
       - After: correctly set *created = 0 (indicating existing queue)
    
    2. When creating a new message queue (inode_find fails):
       - Before: incorrectly set *created = 0 (indicating existing queue)
       - After: correctly set *created = 1 (indicating new creation)
    
    This bug could lead to incorrect resource management and cleanup behavior
    in the calling function nxmq_vopen() when file_allocate() returns an error,
    as it relies on the 'created' flag to determine whether the message queue
    was newly created and needs to be cleaned up.
    
    Impact:
    - Resource leak when opening existing queues that should not be released
    - Missing cleanup when creating new queues that should be released on error
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 fs/mqueue/mq_open.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c
index f51d1eeb3c8..909c4dabf9f 100644
--- a/fs/mqueue/mq_open.c
+++ b/fs/mqueue/mq_open.c
@@ -269,7 +269,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const 
char *mq_name,
 
       if (created)
         {
-          *created = 1;
+          *created = 0;
         }
     }
   else
@@ -321,7 +321,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const 
char *mq_name,
 
       if (created)
         {
-          *created = 0;
+          *created = 1;
         }
     }
 

Reply via email to