Skip to content

Commit

Permalink
manually drop target fd
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Oct 17, 2024
1 parent 3d227c4 commit 482438b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use starknet_types_core::{
felt::Felt,
hash::StarkHash,
};
use std::{collections::HashMap, ffi::c_void, fs::File, io::Write, os::fd::FromRawFd};
use std::{
collections::HashMap, ffi::c_void, fs::File, io::Write, mem::ManuallyDrop, os::fd::FromRawFd,
};
use std::{ops::Mul, vec::IntoIter};

lazy_static! {
Expand All @@ -39,7 +41,8 @@ pub unsafe extern "C" fn cairo_native__libfunc__debug__print(
data: *const [u8; 32],
len: u32,
) -> i32 {
let mut target = File::from_raw_fd(target_fd);
// Avoid closing `stdout` on all branches.
let mut target = ManuallyDrop::new(File::from_raw_fd(target_fd));

let mut items = Vec::with_capacity(len as usize);

Expand All @@ -57,9 +60,6 @@ pub unsafe extern "C" fn cairo_native__libfunc__debug__print(
return 1;
};

// Avoid closing `stdout`.
std::mem::forget(target);

0
}

Expand Down

0 comments on commit 482438b

Please sign in to comment.