Stop worker threads on memory trim & fix bad pointer access

Change-Id: I6fe7e31aeb6dd41fa65ab952caed97bc2da510d7
diff --git a/libs/hwui/thread/TaskManager.cpp b/libs/hwui/thread/TaskManager.cpp
index ce6c8c0..c8bfd9c 100644
--- a/libs/hwui/thread/TaskManager.cpp
+++ b/libs/hwui/thread/TaskManager.cpp
@@ -48,6 +48,12 @@
     return mThreads.size() > 0;
 }
 
+void TaskManager::stop() {
+    for (size_t i = 0; i < mThreads.size(); i++) {
+        mThreads[i]->exit();
+    }
+}
+
 bool TaskManager::addTaskBase(const sp<TaskBase>& task, const sp<TaskProcessorBase>& processor) {
     if (mThreads.size() > 0) {
         TaskWrapper wrapper(task, processor);