diff options
author | Alan Jeon <skyisle@gmail.com> | 2014-10-16 17:05:25 +0900 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-05-11 16:28:04 -0700 |
commit | 4af3c40c4a5343ea30c8f600cc61804b8fb39bb6 (patch) | |
tree | c471fb73dcedcdc9594611edd54bbc5e3fd8b710 /adb/services.cpp | |
parent | 97d0c1935447b4fc91bd59f604ab92e9e579efa3 (diff) | |
download | core-4af3c40c4a5343ea30c8f600cc61804b8fb39bb6.tar.gz core-4af3c40c4a5343ea30c8f600cc61804b8fb39bb6.tar.bz2 core-4af3c40c4a5343ea30c8f600cc61804b8fb39bb6.zip |
adb: Do not share memory between multiple thread
When multiple client try to connect to other hosts, it failed because
memory corruption. Allocate memory for each thread like other command did.
Change-Id: I79959ce3dbfd11c7553736cd3f5a899815873584
Signed-off-by: Alan Jeon <skyisle@gmail.com>
Diffstat (limited to 'adb/services.cpp')
-rw-r--r-- | adb/services.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/adb/services.cpp b/adb/services.cpp index e53a28c2d..b86947923 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -618,16 +618,15 @@ void connect_emulator(const std::string& port_spec, std::string* response) { } } -static void connect_service(int fd, void* cookie) -{ - char *host = reinterpret_cast<char*>(cookie); - +static void connect_service(int fd, void* data) { + char* host = reinterpret_cast<char*>(data); std::string response; if (!strncmp(host, "emu:", 4)) { connect_emulator(host + 4, &response); } else { connect_device(host, &response); } + free(host); // Send response for emulator and device SendProtocolString(fd, response); @@ -664,6 +663,9 @@ asocket* host_service_to_socket(const char* name, const char *serial) sinfo->transport_type = kTransportAny; sinfo->state = CS_DEVICE; } else { + if (sinfo->serial) { + free(sinfo->serial); + } free(sinfo); return NULL; } @@ -671,8 +673,8 @@ asocket* host_service_to_socket(const char* name, const char *serial) int fd = create_service_thread(wait_for_state, sinfo); return create_local_socket(fd); } else if (!strncmp(name, "connect:", 8)) { - const char *host = name + 8; - int fd = create_service_thread(connect_service, (void *)host); + char* host = strdup(name + 8); + int fd = create_service_thread(connect_service, host); return create_local_socket(fd); } return NULL; |