From 64d5edce92dc27cfef11594a27876cd378225e53 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 28 Mar 2020 23:25:38 +0100 Subject: [PATCH] Refactor server_start() error handling This avoids cleanup duplication. --- app/src/server.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/server.c b/app/src/server.c index 89bf9c72..2923c6c7 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -345,30 +345,31 @@ server_start(struct server *server, const char *serial, } if (!push_server(serial)) { - SDL_free(server->serial); - return false; + goto error1; } if (!enable_tunnel_any_port(server, params->port_range)) { - SDL_free(server->serial); - return false; + goto error1; } // server will connect to our server socket server->process = execute_server(server, params); - if (server->process == PROCESS_NONE) { - if (!server->tunnel_forward) { - close_socket(&server->server_socket); - } - disable_tunnel(server); - SDL_free(server->serial); - return false; + goto error2; } server->tunnel_enabled = true; return true; + +error2: + if (!server->tunnel_forward) { + close_socket(&server->server_socket); + } + disable_tunnel(server); +error1: + SDL_free(server->serial); + return false; } bool