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

acassis 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 cf4a9d72411 drivers/serial/pty: fix memory leak when pty_destroy
cf4a9d72411 is described below

commit cf4a9d7241163866a233c5f5af28b213ee4fef93
Author: ligd <[email protected]>
AuthorDate: Sat Jan 18 17:47:53 2025 +0800

    drivers/serial/pty: fix memory leak when pty_destroy
    
    1. ptmx_open -> pty_register2 -> master register i_crefs 1
                                  -> salve  register i_crefs 1
    2. ptmx_open -> master unregister i_crefs 0
    3. master open i_crefs 1
       salve  open i_crefs 2
    
    4. in pty_close() master close with i_crefs 1
                      salve  close with i_crefs 2
    
    So, if correct the i_crefs judgement in pty_close()
    
    Signed-off-by: ligd <[email protected]>
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 drivers/serial/pty.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index 4b04b2fd7b6..bcefb1672fe 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -340,7 +340,8 @@ static int pty_close(FAR struct file *filep)
 
   /* Check if the decremented inode reference count would go to zero */
 
-  if (atomic_read(&inode->i_crefs) == 1)
+  if ((!dev->pd_master && atomic_load(&inode->i_crefs) == 2) ||
+       (dev->pd_master && atomic_load(&inode->i_crefs) == 1))
     {
       /* Did the (single) master just close its reference? */
 

Reply via email to