mirror of
https://github.com/lune-org/lune.git
synced 2025-04-11 22:10:53 +01:00
feat: avoid leaking and use a Vec
instead (thanks @filiptibell)
This commit is contained in:
parent
ac87772e61
commit
47d39cb8a9
2 changed files with 5 additions and 5 deletions
|
@ -200,10 +200,10 @@ async fn process_spawn(
|
|||
async fn spawn_command(
|
||||
program: String,
|
||||
args: Option<Vec<String>>,
|
||||
options: ProcessSpawnOptions,
|
||||
mut options: ProcessSpawnOptions,
|
||||
) -> LuaResult<(ExitStatus, Vec<u8>, Vec<u8>)> {
|
||||
let inherit_stdio = options.inherit_stdio;
|
||||
let stdin = options.stdin;
|
||||
let stdin = options.stdin.take();
|
||||
|
||||
let mut child = options
|
||||
.into_command(program, args)
|
||||
|
@ -218,7 +218,7 @@ async fn spawn_command(
|
|||
// If the stdin option was provided, we write that to the child
|
||||
if let Some(stdin) = stdin {
|
||||
let mut child_stdin = child.stdin.take().unwrap();
|
||||
child_stdin.write_all(stdin).await.into_lua_err()?;
|
||||
child_stdin.write_all(&stdin).await.into_lua_err()?;
|
||||
}
|
||||
|
||||
if inherit_stdio {
|
||||
|
|
|
@ -14,7 +14,7 @@ pub struct ProcessSpawnOptions {
|
|||
pub(crate) envs: HashMap<String, String>,
|
||||
pub(crate) shell: Option<String>,
|
||||
pub(crate) inherit_stdio: bool,
|
||||
pub(crate) stdin: Option<&'static [u8]>,
|
||||
pub(crate) stdin: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl<'lua> FromLua<'lua> for ProcessSpawnOptions {
|
||||
|
@ -139,7 +139,7 @@ impl<'lua> FromLua<'lua> for ProcessSpawnOptions {
|
|||
*/
|
||||
match value.get("stdin")? {
|
||||
LuaValue::Nil => {}
|
||||
LuaValue::String(s) => this.stdin = Some(&*(s.as_bytes().to_vec().leak())),
|
||||
LuaValue::String(s) => this.stdin = Some(s.as_bytes().to_vec()),
|
||||
value => {
|
||||
return Err(LuaError::RuntimeError(format!(
|
||||
"Invalid type for option 'stdin' - expected 'string', got '{}'",
|
||||
|
|
Loading…
Add table
Reference in a new issue