Skip to content

Commit

Permalink
Fix resource leak when a Thread is restarted.
Browse files Browse the repository at this point in the history
Pthread's own memory resource (created from mmap) must be cleaned up by
one of following ways:
  - pthread_join
  - pthread_detach (and wait for thread's termination)

Previously these methods were not invoked at all when Thread's Start
method is called repeatedly.

As a result, per-thread memory resource was leaked.  The leak (Android
version) could be observed by:
  0. Launch the app.
  1. Show the s/w keyboard and hide it.
  2. `adb shell cat /proc/${YOUR_PID}/maps > /tmp/map.1`
  3. Show the s/w keyboard and hide it.
  4. `adb shell cat /proc/${YOUR_PID}/maps > /tmp/map.2`
  5. `diff /tmp/map.1 /tmp/map.2`

Following lines in diff for example.
  9a6a9000-9a6aa000 ---p 00000000 00:00 0
  9a6aa000-9a7a8000 rw-p 00000000 00:00 0
  9a7a8000-9a7a9000 ---p 00000000 00:00 0
  9a7a9000-9a8a7000 rw-p 00000000 00:00 0

Closes #355.

BUG=#355
TEST=manually done with Android 6.0.1 MMB29S and Nexus 5 2013
REF_BUG=26499803
REF_CL=112025510
  • Loading branch information
matsuza authored and yukawa committed Jan 16, 2016
1 parent 3306d33 commit d938fbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/base/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ bool Thread::IsRunning() const {
}

void Thread::Detach() {
state_->handle_.reset(nullptr);
if (state_->handle_ != nullptr) {
pthread_detach(*state_->handle_);
state_->handle_.reset(nullptr);
}
}

void Thread::Join() {
Expand Down
2 changes: 1 addition & 1 deletion src/mozc_version_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=17
BUILD=2313
BUILD=2314
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.
Expand Down

0 comments on commit d938fbb

Please sign in to comment.