Skip to content

Commit 2d8cdc3

Browse files
committed
close the pipe in the case of failure when setting its size
1 parent c8bbb0e commit 2d8cdc3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/pipe.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io;
1+
use std::{io, ptr::null_mut};
22

33
pub const PIPE_BUF_SIZE: usize = 1 << 20;
44

@@ -23,7 +23,10 @@ impl Pipe {
2323
};
2424

2525
unsafe {
26-
if libc::fcntl(pipes[0], libc::F_SETPIPE_SZ, 1 << 20) < 0 {
26+
if libc::fcntl(pipes[0], libc::F_SETPIPE_SZ, PIPE_BUF_SIZE) < 0 {
27+
libc::close(pipes[0]);
28+
libc::close(pipes[1]);
29+
2730
return Err(io::Error::last_os_error());
2831
}
2932
}
@@ -48,9 +51,9 @@ pub fn splice(r: i32, w: i32, n: usize) -> isize {
4851
unsafe {
4952
libc::splice(
5053
r,
51-
std::ptr::null_mut::<libc::loff_t>(),
54+
null_mut::<libc::loff_t>(),
5255
w,
53-
std::ptr::null_mut::<libc::loff_t>(),
56+
null_mut::<libc::loff_t>(),
5457
n,
5558
libc::SPLICE_F_MOVE | libc::SPLICE_F_NONBLOCK,
5659
)

0 commit comments

Comments
 (0)