Skip to content

Commit

Permalink
fixup: pty: possible memory leaking on close()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
polarvid authored and mysterywolf committed Sep 20, 2024
1 parent 8790649 commit 210cd71
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions components/lwp/terminal/tty_ptmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
/**
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 210cd71

Please sign in to comment.