diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 17:10:32 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 17:10:32 -0700 |
commit | 957b61f582ce59d19bdae54c41600a76b0dcc2e7 (patch) | |
tree | 7f4c9eeec18ff3642a2cf8fd7ba161551cf830ce | |
parent | 99839fc6869e37c8e2dc3ea960b5c19f28bd8a5e (diff) | |
download | dartboat-957b61f582ce59d19bdae54c41600a76b0dcc2e7.tar.gz dartboat-957b61f582ce59d19bdae54c41600a76b0dcc2e7.tar.xz |
web: fix memory leak when undone match ends in fewer visits
-rw-r--r-- | web/dartboat_wasm.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c index 200621e..e624c67 100644 --- a/web/dartboat_wasm.c +++ b/web/dartboat_wasm.c @@ -258,7 +258,8 @@ EMSCRIPTEN_KEEPALIVE bool user_undo() { EM_ASM({updatePlayerAvg($0, $1)}, P_USER, l->n_visits ? (double)(l->start-l->rem)/l->n_visits : 0); EM_ASM({updatePlayerAvg($0, $1)}, P_BOAT, - state->l2->n_visits ? (double)(state->l2->start-state->l2->rem)/state->l2->n_visits : 0); + state->l2->n_visits ? + (double)(state->l2->start-state->l2->rem)/state->l2->n_visits : 0); update_user_rem(l->rem); update_boat_rem(state->l2->rem); @@ -274,7 +275,8 @@ EMSCRIPTEN_KEEPALIVE void draw_boat_throwing(int pts, char *str) { char buf[10]; sprintf(buf, "%d", pts); - int rem = state->l2->n_visits > 1 ? state->l2->visits[state->l2->n_visits-2].rem : state->l2->start; + int rem = state->l2->n_visits > 1 ? + state->l2->visits[state->l2->n_visits-2].rem : state->l2->start; update_boat_rem(rem - pts); EM_ASM({setPromptInput($0)}, buf); @@ -323,6 +325,7 @@ void init_boat() { EMSCRIPTEN_KEEPALIVE void free_match() { leg_free(state->l1); + state->l2->n_visits += undone_count; // FIXME messy way to avoid memory leak leg_free(state->l2); free(state); state = NULL; |