Display and control your Android device
Fix memory leak on portable builds
Romain Vimont7d5845196e6a
diff --git a/app/src/server.c b/app/src/server.cindex ff167aeb..31e09ae3 100644--- a/app/src/server.c+++ b/app/src/server.c@@ -18,20 +18,31 @@#define DEFAULT_SERVER_PATH PREFIX "/share/scrcpy/" SERVER_FILENAME#define DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"-static const char *+static char *get_server_path(void) {const char *server_path_env = getenv("SCRCPY_SERVER_PATH");if (server_path_env) {- LOGD("Using SCRCPY_SERVER_PATH: %s", server_path_env);// if the envvar is set, use it- return server_path_env;+ char *server_path = SDL_strdup(server_path_env);+ if (!server_path) {+ LOGE("Could not allocate memory");+ return NULL;+ }+ LOGD("Using SCRCPY_SERVER_PATH: %s", server_path);+ return server_path;}#ifndef PORTABLELOGD("Using server: " DEFAULT_SERVER_PATH);+ char *server_path = SDL_strdup(DEFAULT_SERVER_PATH);+ if (!server_path) {+ LOGE("Could not allocate memory");+ return NULL;+ }// the absolute path is hardcoded- return DEFAULT_SERVER_PATH;+ return server_path;#else+// use scrcpy-server in the same directory as the executablechar *executable_path = get_executable_path();if (!executable_path) {@@ -67,12 +78,17 @@ get_server_path(void) {static boolpush_server(const char *serial) {- const char *server_path = get_server_path();+ char *server_path = get_server_path();+ if (!server_path) {+ return false;+ }if (!is_regular_file(server_path)) {LOGE("'%s' does not exist or is not a regular file\n", server_path);+ SDL_free(server_path);return false;}process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH);+ SDL_free(server_path);return process_check_success(process, "adb push");}