summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShell <[email protected]>2024-09-19 15:06:03 +0800
committerMeco Man <[email protected]>2024-09-19 23:02:25 -0400
commit210cd71128f3b3208bab5ed3844c09e588f89711 (patch)
tree80cada86d11c1e2db0d2a20553dde160a4e1c21a
parent87906499a387101e2f5b04f36fba8a3d21f25a8c (diff)
fixup: pty: possible memory leaking on close()
The ref_count of the vnode is NOT bound to the resource reference counts of the ptm device created by opening `dev/ptmx`, so the conditional release of resource may end up by memory leaking if the multiple user have open the `dev/ptmx`. Changes: - Removed conditional branch on recycling resource Signed-off-by: Shell <[email protected]>
-rw-r--r--components/lwp/terminal/tty_ptmx.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/components/lwp/terminal/tty_ptmx.c b/components/lwp/terminal/tty_ptmx.c
index 8daebc099a..371c27a26b 100644
--- a/components/lwp/terminal/tty_ptmx.c
+++ b/components/lwp/terminal/tty_ptmx.c
@@ -27,7 +27,6 @@ static int ptm_fops_open(struct dfs_file *file)
rt_uint32_t oflags = file->flags;
rt_thread_t cur_thr = rt_thread_self();
- /* we don't check refcnt because each open will create a new device */
if (file->vnode && file->vnode->data)
{
/**
@@ -62,16 +61,9 @@ static int ptm_fops_close(struct dfs_file *file)
if (file->data)
{
- if (file->vnode->ref_count != 1)
- {
- rc = 0;
- }
- else
- {
- device = (rt_device_t)file->data;
- tp = rt_container_of(device, struct lwp_tty, parent);
- rc = bsd_ptsdev_methods.fo_close(tp, rt_thread_self());
- }
+ device = (rt_device_t)file->data;
+ tp = rt_container_of(device, struct lwp_tty, parent);
+ rc = bsd_ptsdev_methods.fo_close(tp, rt_thread_self());
}
else
{