aboutsummaryrefslogtreecommitdiffstats
path: root/moder.c
diff options
context:
space:
mode:
authorTeddy Wing2018-09-04 16:15:14 +0200
committerTeddy Wing2018-09-06 04:03:20 +0200
commitce1eca32e2249a72692c6eb01052361d98af29c3 (patch)
treeb24d1c6f68d72664e31d6a8952b3ae83fdc1ed2e /moder.c
parent84d29715900209b8ab4c600ad40ef99cdad03bd6 (diff)
downloaddome-key-map-ce1eca32e2249a72692c6eb01052361d98af29c3.tar.bz2
c_run_key_action(): Fix segfault on `in_mode`
Finally figured out where the problem was with the `in_mode` on my `CKeyActionResult` getting freed too early. It happens because we're trying to use the reference to the `in_mode` slice from the `KeyActionResult` returned by `run_key_action_for_mode()`. We were putting that reference in the `in_mode` of the `CKeyActionResult` returned by `c_run_key_action()`, but it would get freed in that function. In order to make it last indefinitely, we needed to convert it into a raw boxed pointer to prevent Rust from deallocating it. This does mean we now have a memory leak, but we'll just have to make a call into Rust to free it from the C code.
Diffstat (limited to 'moder.c')
-rw-r--r--moder.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/moder.c b/moder.c
index c50a7d5..1dd4e52 100644
--- a/moder.c
+++ b/moder.c
@@ -10,7 +10,7 @@ int main() {
.length = SIZE
};
const CKeyActionResult *mode = c_run_key_action(mode_trigger, NULL);
- /* printf("%d\n", *mode->kind); */
+ printf("%d\n", *mode->kind);
HeadphoneButton buttons[] = {HeadphoneButton_Down};
Trigger trigger = {
@@ -21,6 +21,7 @@ int main() {
printf("%d\n", *result->kind);
printf("%s", result->action);
+ /* printf("\n%d\n", *mode->kind); */
return 0;
}