From c3570c1377b18ca2c8e921dee2b3eaa9a0b7da49 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 25 Jan 2020 16:41:20 +0000 Subject: [PATCH] Alias based command implementations are not checked for variable leaks --- CHANGELOG.md | 1 + duckscript_sdk/src/types/command.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4245fa4..9823825 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### v0.1.9 +* Alias based command implementations are not checked for variable leaks. * New get_home_dir command. * New array_join command. * The read_properties command now support **--prefix** flag. diff --git a/duckscript_sdk/src/types/command.rs b/duckscript_sdk/src/types/command.rs index f234903..7e53123 100644 --- a/duckscript_sdk/src/types/command.rs +++ b/duckscript_sdk/src/types/command.rs @@ -90,6 +90,8 @@ impl Command for AliasCommand { if arguments.len() < self.arguments_amount { CommandResult::Error("Invalid arguments provided.".to_string()) } else { + let start_count = variables.len(); + // define script arguments let mut handle_option = None; if !arguments.is_empty() { @@ -198,9 +200,20 @@ impl Command for AliasCommand { } clear(&self.scope_name, variables); - match flow_result { - Some(result) => result, - None => CommandResult::Continue(flow_output), + let end_count = variables.len(); + if start_count != end_count { + CommandResult::Crash( + format!( + "Memory leak detected, delta variables count: {}", + end_count - start_count + ) + .to_string(), + ) + } else { + match flow_result { + Some(result) => result, + None => CommandResult::Continue(flow_output), + } } } }