Refactor server_start() error handling
This avoids cleanup duplication.
@@ -345,32 +345,33 @@ 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) {
+ 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;
}
- server->tunnel_enabled = true;
-
- return true;
-}
-
bool
server_connect_to(struct server *server) {
if (!server->tunnel_forward) {
