summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-25 13:38:41 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-25 14:54:31 +0100
commit9f2a67841a4ca37b0c95e5eb2b6558a6981785a6 (patch)
tree329d2c0a20a9f19752c84dc0017c3326701328f0
parent708c7b26b12364434316a5435b01a2c3869bfc6f (diff)
Fix: Remove Box::leak() call in runtime application abstraction
This patch removes the leakage in the runtime application abstraction. Also fix formatting. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/core/libimagrt/src/application.rs22
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/core/libimagrt/src/application.rs b/lib/core/libimagrt/src/application.rs
index 74ad4b68..e1de1fe2 100644
--- a/lib/core/libimagrt/src/application.rs
+++ b/lib/core/libimagrt/src/application.rs
@@ -37,34 +37,24 @@ macro_rules! simple_imag_application_binary {
extern crate failure;
extern crate $application_library;
- use failure::{Error, Fallible as Result};
-
+ use failure::{Error, Fallible as Result, ResultExt};
+
fn main() {
use libimagerror::trace::MapErrTrace;
use libimagrt::application::ImagApplication;
use libimagrt::setup::generate_runtime_setup;
use $application_library::$application_implementor;
-
+
let version = make_imag_version!();
let rt = generate_runtime_setup($application_implementor::name(),
&version,
$application_implementor::description(),
$application_implementor::build_cli);
- // The error context must have a 'static lifetime
- // Therefore, the easiest, safe, but hacky way to achieve this
- // is to allocate a string, which is then forgotten to
- // leak memory and return it's contents as a &'static str
- // Because this is the very end of the application and only
- // happens once, it should have no impact whatsoever
- let error_context: &'static str = Box::leak(
- format!("Failed to run {}", $application_implementor::name())
- .into_boxed_str()
- );
$application_implementor::run(rt)
- .map_err(|e| e.context(error_context))
- .map_err(Error::from)
- .map_err_trace_exit_unwrap();
+ .context(format!("Failed to run {}", $application_implementor::name()))
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap();
}
};
}