Fix SEGV when allocation does not fail in stack trace building

Change-Id: Ic01f95d4b4b90b38510c448b05d2efbac95d9c7c
diff --git a/src/exception_test.cc b/src/exception_test.cc
index adb32d1..22ae682 100644
--- a/src/exception_test.cc
+++ b/src/exception_test.cc
@@ -140,10 +140,13 @@
 
   JNIEnv* env = thread->GetJniEnv();
   jobject internal = thread->CreateInternalStackTrace(env);
+  ASSERT_TRUE(internal != NULL);
   jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(env, internal);
+  ASSERT_TRUE(ste_array != NULL);
   ObjectArray<StackTraceElement>* trace_array =
       Decode<ObjectArray<StackTraceElement>*>(env, ste_array);
 
+  ASSERT_TRUE(trace_array != NULL);
   ASSERT_TRUE(trace_array->Get(0) != NULL);
   EXPECT_STREQ("ExceptionHandle",
                trace_array->Get(0)->GetDeclaringClass()->ToModifiedUtf8().c_str());
diff --git a/src/thread.cc b/src/thread.cc
index 4a8381d..82ee631 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -1074,7 +1074,7 @@
     }
 #ifdef MOVING_GARBAGE_COLLECTOR
     // Re-read after potential GC
-    method_trace = Decode<ObjectArray<Object>*>(ts.Env(), local_ref_);
+    method_trace_ = Decode<ObjectArray<Object>*>(ts.Env(), local_ref_);
 #endif
     // Save PC trace in last element of method trace, also places it into the
     // object graph.
@@ -1210,12 +1210,11 @@
 
   // Build internal stack trace
   BuildInternalStackTraceVisitor build_trace_visitor(depth);
-  if (build_trace_visitor.Init(skip_depth, ts)) {
+  if (!build_trace_visitor.Init(skip_depth, ts)) {
     return NULL;  // Allocation failed
-  } else {
-    WalkStack(&build_trace_visitor);
-    return build_trace_visitor.GetInternalStackTrace();
   }
+  WalkStack(&build_trace_visitor);
+  return build_trace_visitor.GetInternalStackTrace();
 }
 
 jobjectArray Thread::InternalStackTraceToStackTraceElementArray(JNIEnv* env, jobject internal,