diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2023-08-14 09:44:23 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2023-08-14 10:13:07 +0000 |
| commit | b1d81e1b1fd59519119dc3e77333d51b0d5b2458 (patch) | |
| tree | 0de1d98deb4e3d200811159c60f6823762b44f14 /src/state.c | |
| parent | b88e3cb9e61aaa151d2072879e3382cb3af3485e (diff) | |
Add memory freeing to input contexts
Diffstat (limited to 'src/state.c')
| -rw-r--r-- | src/state.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/state.c b/src/state.c index ceb21e6..47752bc 100644 --- a/src/state.c +++ b/src/state.c @@ -49,6 +49,8 @@ extern state_##name##_update_t name##_update; #include <states/all_states.h> +void binding_t_free(binding_t* b); + void State_init(StateType type, memory *mem) { switch (type) { #define State(name) \ @@ -283,3 +285,34 @@ bool State_reload(StateType type, i_ctx **ctx, usize ctx_len) { //ctx = &ctx_cpy; } #endif + +void i_ctx_t_free(i_ctx* c) { + for (isize i = 0; i < c->len; i++) { + binding_t_free(&c->bindings[i]); + } +} + +void binding_t_free(binding_t* b) { + switch (b->action.type) { + case InputType_error: + ERROR("Cannot free binding of type InputType_error"); + break; + case InputType_action: + free(b->action.action.callback_str); + return; + + case InputType_state: + free(b->action.state.activate_str); + free(b->action.state.deactivate_str); + break; + + case InputType_range: + ERROR("Cannot free binding of type InputType_rage"); + break; + + default: + ERROR("Unknown bindings type"); + break; + } + exit(EXIT_FAILURE); +} |
