mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 14:58:13 +08:00
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 <liguiding1@xiaomi.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -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? */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user