diff options
| author | Teddy Wing | 2018-10-06 00:32:28 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-10-06 00:32:28 +0200 |
| commit | 60809b7884621cb949eec3ddbe1eae76103d17c2 (patch) | |
| tree | d22907ae75cd72ee2713af693dff78a20a2ffbc8 | |
| parent | c231864f9a8c5242d2877ad56f069199082e78b1 (diff) | |
| download | dome-key-map-60809b7884621cb949eec3ddbe1eae76103d17c2.tar.bz2 | |
c_parse_args(): Box the returned `Config` pointer
Otherwise it gets freed too early by Rust. Add (re-add) a free function
for it too now that we know it must be freed manually.
| -rw-r--r-- | dome_key_map.h | 2 | ||||
| -rw-r--r-- | src/cocoa_bridge.rs | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/dome_key_map.h b/dome_key_map.h index 8701b4a..8323fdd 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -37,6 +37,8 @@ const Config *c_parse_args(const char *const *args, size_t length); void c_run_key_action(State *state, Trigger trigger, const Trigger *mode); +void config_free(Config *ptr); + void logger_init(void); void state_free(State *ptr); diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 2ef4979..70d837a 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -322,7 +322,13 @@ pub extern "C" fn c_parse_args( let config = config::parse_args(&args); - &config as *const Config + Box::into_raw(Box::new(config)) +} + +#[no_mangle] +pub extern "C" fn config_free(ptr: *mut Config) { + if ptr.is_null() { return } + unsafe { Box::from_raw(ptr); } } |
