Skip to content

Commit 055061a

Browse files
committed
[DeviceDrivers] Fix pipe memory issue.
1 parent 78d42ef commit 055061a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

components/drivers/src/pipe.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
static int pipe_fops_open(struct dfs_fd *fd)
2121
{
22+
int rc = 0;
2223
rt_device_t device;
2324
rt_pipe_t *pipe;
2425

@@ -31,6 +32,11 @@ static int pipe_fops_open(struct dfs_fd *fd)
3132
if (device->ref_count == 0)
3233
{
3334
pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
35+
if (pipe->fifo == RT_NULL)
36+
{
37+
rc = -RT_ENOMEM;
38+
goto __exit;
39+
}
3440
}
3541

3642
switch (fd->flags & O_ACCMODE)
@@ -48,9 +54,10 @@ static int pipe_fops_open(struct dfs_fd *fd)
4854
}
4955
device->ref_count ++;
5056

57+
__exit:
5158
rt_mutex_release(&(pipe->lock));
5259

53-
return 0;
60+
return rc;
5461
}
5562

5663
static int pipe_fops_close(struct dfs_fd *fd)
@@ -90,7 +97,8 @@ static int pipe_fops_close(struct dfs_fd *fd)
9097

9198
if (device->ref_count == 1)
9299
{
93-
rt_ringbuffer_destroy(pipe->fifo);
100+
if (pipe->fifo != RT_NULL)
101+
rt_ringbuffer_destroy(pipe->fifo);
94102
pipe->fifo = RT_NULL;
95103
}
96104
device->ref_count --;

0 commit comments

Comments
 (0)