From 957b61f582ce59d19bdae54c41600a76b0dcc2e7 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 23 Apr 2022 17:10:32 -0700 Subject: web: fix memory leak when undone match ends in fewer visits --- web/dartboat_wasm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'web') 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; -- cgit v1.2.3-70-g09d2