Skip to content

Commit 210cd71

Browse files
polarvidmysterywolf
authored andcommitted
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]>
1 parent 8790649 commit 210cd71

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

components/lwp/terminal/tty_ptmx.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ static int ptm_fops_open(struct dfs_file *file)
2727
rt_uint32_t oflags = file->flags;
2828
rt_thread_t cur_thr = rt_thread_self();
2929

30-
/* we don't check refcnt because each open will create a new device */
3130
if (file->vnode && file->vnode->data)
3231
{
3332
/**
@@ -62,16 +61,9 @@ static int ptm_fops_close(struct dfs_file *file)
6261

6362
if (file->data)
6463
{
65-
if (file->vnode->ref_count != 1)
66-
{
67-
rc = 0;
68-
}
69-
else
70-
{
71-
device = (rt_device_t)file->data;
72-
tp = rt_container_of(device, struct lwp_tty, parent);
73-
rc = bsd_ptsdev_methods.fo_close(tp, rt_thread_self());
74-
}
64+
device = (rt_device_t)file->data;
65+
tp = rt_container_of(device, struct lwp_tty, parent);
66+
rc = bsd_ptsdev_methods.fo_close(tp, rt_thread_self());
7567
}
7668
else
7769
{

0 commit comments

Comments
 (0)