From ec0282304511456a88117a97b4bdba4075486080 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 26 May 2018 14:20:05 +0200 Subject: [PATCH] Fix leak on server start error Fail on SDL_strdup() failure, and free the duplicated serial on further error. --- app/src/server.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/server.c b/app/src/server.c index a35f5d1f..53ca1b40 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -152,15 +152,20 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po if (serial) { server->serial = SDL_strdup(serial); + if (!server->serial) { + return SDL_FALSE; + } } if (!push_server(serial)) { + SDL_free((void *) server->serial); return SDL_FALSE; } server->server_copied_to_device = SDL_TRUE; if (!enable_tunnel(server)) { + SDL_free((void *) server->serial); 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) { LOGE("Could not listen on port %" PRIu16, local_port); disable_tunnel(server); + SDL_free((void *) server->serial); 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); } disable_tunnel(server); + SDL_free((void *) server->serial); return SDL_FALSE; }