From c8a3c80603d4a78ff1f3c87dbf4206ac4306b150 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Tue, 29 Sep 2015 18:05:30 -0700 Subject: [PATCH] minadbd: use strdup() to create argument for sideload thread. So sideload thread will not use argument which is to be freed in the main thread. Bug: 23968770 Change-Id: I9d6dadc6c33cfbe4b5759382a80fe14cd0d54355 --- minadbd/services.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/minadbd/services.cpp b/minadbd/services.cpp index 2a3027bd..d25648fb 100644 --- a/minadbd/services.cpp +++ b/minadbd/services.cpp @@ -43,13 +43,14 @@ void* service_bootstrap_func(void* x) { } static void sideload_host_service(int sfd, void* data) { - const char* args = reinterpret_cast(data); + char* args = reinterpret_cast(data); int file_size; int block_size; if (sscanf(args, "%d:%d", &file_size, &block_size) != 2) { printf("bad sideload-host arguments: %s\n", args); exit(1); } + free(args); printf("sideload-host file size %d block size %d\n", file_size, block_size); @@ -94,7 +95,8 @@ int service_to_fd(const char* name, const atransport* transport) { // sideload-host). exit(3); } else if (!strncmp(name, "sideload-host:", 14)) { - ret = create_service_thread(sideload_host_service, (void*)(name + 14)); + char* arg = strdup(name + 14); + ret = create_service_thread(sideload_host_service, arg); } if (ret >= 0) { close_on_exec(ret);