Skip to content
Snippets Groups Projects
Commit 7e4a60f7 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Fix possible deadlocks

parent 658dc34d
No related branches found
No related tags found
No related merge requests found
Pipeline #1363 failed
...@@ -307,9 +307,7 @@ pub extern "C" fn ferror(stream: &mut FILE) -> c_int { ...@@ -307,9 +307,7 @@ pub extern "C" fn ferror(stream: &mut FILE) -> c_int {
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fflush(stream: &mut FILE) -> c_int { pub unsafe extern "C" fn fflush(stream: &mut FILE) -> c_int {
flockfile(stream); flockfile(stream);
let ret = helpers::fflush_unlocked(stream); let ret = helpers::fflush_unlocked(stream);
funlockfile(stream); funlockfile(stream);
ret ret
} }
...@@ -362,6 +360,7 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c ...@@ -362,6 +360,7 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c
{ {
// We can't read from this stream // We can't read from this stream
if !stream.can_read() { if !stream.can_read() {
funlockfile(stream);
return ptr::null_mut(); return ptr::null_mut();
} }
} }
...@@ -408,8 +407,9 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c ...@@ -408,8 +407,9 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c
#[no_mangle] #[no_mangle]
pub extern "C" fn fileno(stream: &mut FILE) -> c_int { pub extern "C" fn fileno(stream: &mut FILE) -> c_int {
flockfile(stream); flockfile(stream);
let fd = stream.fd;
funlockfile(stream); funlockfile(stream);
stream.fd fd
} }
/// Lock the file /// Lock the file
...@@ -483,6 +483,7 @@ pub extern "C" fn fread(ptr: *mut c_void, size: usize, nitems: usize, stream: &m ...@@ -483,6 +483,7 @@ pub extern "C" fn fread(ptr: *mut c_void, size: usize, nitems: usize, stream: &m
flockfile(stream); flockfile(stream);
if !stream.can_read() { if !stream.can_read() {
funlockfile(stream);
return 0; return 0;
} }
...@@ -601,6 +602,7 @@ pub extern "C" fn fseeko(stream: &mut FILE, offset: off_t, whence: c_int) -> c_i ...@@ -601,6 +602,7 @@ pub extern "C" fn fseeko(stream: &mut FILE, offset: off_t, whence: c_int) -> c_i
} }
stream.write = None; stream.write = None;
if stream.seek(off, whence) < 0 { if stream.seek(off, whence) < 0 {
funlockfile(stream);
return -1; return -1;
} }
stream.read = None; stream.read = None;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment