Mon, 13 Jul 2026 22:16:52 +0200
fix memory leaks in server_run() when starting the game is aborted
| src/main.c | file | annotate | diff | comparison | revisions |
--- a/src/main.c Mon Jul 13 22:13:34 2026 +0200 +++ b/src/main.c Mon Jul 13 22:16:52 2026 +0200 @@ -1047,6 +1047,7 @@ settings_apply(&gamestate); if (settings.continuepgn) { /* preload PGN data before handshake */ + bool cancel = false; FILE *pgnfile = fopen(settings.continuepgn, "r"); if (pgnfile) { int result = read_pgn(pgnfile, &gamestate); @@ -1055,14 +1056,17 @@ if (result) { printw("Invalid PGN file content at position %ld:\n%s\n", position, pgn_error_str(result)); - return 1; - } - if (!is_game_running(&gamestate)) { + cancel = true; + } else if (!is_game_running(&gamestate)) { addstr("Game has ended. Use -s to analyze it locally.\n"); - return 1; + cancel = true; } } else { printw("Can't read PGN file (%s)\n", strerror(errno)); + cancel = true; + } + if (cancel) { + gamestate_cleanup(&gamestate); return 1; } } @@ -1070,11 +1074,13 @@ if (server_open(&server)) { net_destroy(&server); + gamestate_cleanup(&gamestate); return 1; } if (server_handshake(server.client)) { net_destroy(&server); + gamestate_cleanup(&gamestate); return 1; }