Fix leak on server start error

Fail on SDL_strdup() failure, and free the duplicated serial on further
error.
This commit is contained in:
Romain Vimont 2018-05-26 14:20:05 +02:00
parent 435a7fe314
commit ec02823045

View file

@ -152,15 +152,20 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
if (serial) { if (serial) {
server->serial = SDL_strdup(serial); server->serial = SDL_strdup(serial);
if (!server->serial) {
return SDL_FALSE;
}
} }
if (!push_server(serial)) { if (!push_server(serial)) {
SDL_free((void *) server->serial);
return SDL_FALSE; return SDL_FALSE;
} }
server->server_copied_to_device = SDL_TRUE; server->server_copied_to_device = SDL_TRUE;
if (!enable_tunnel(server)) { if (!enable_tunnel(server)) {
SDL_free((void *) server->serial);
return SDL_FALSE; return SDL_FALSE;
} }
@ -177,6 +182,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
if (server->server_socket == INVALID_SOCKET) { if (server->server_socket == INVALID_SOCKET) {
LOGE("Could not listen on port %" PRIu16, local_port); LOGE("Could not listen on port %" PRIu16, local_port);
disable_tunnel(server); disable_tunnel(server);
SDL_free((void *) server->serial);
return SDL_FALSE; return SDL_FALSE;
} }
} }
@ -188,6 +194,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
close_socket(&server->server_socket); close_socket(&server->server_socket);
} }
disable_tunnel(server); disable_tunnel(server);
SDL_free((void *) server->serial);
return SDL_FALSE; return SDL_FALSE;
} }