OSDN Git Service

Check for a NULL pointer, do not call Build.
authorChristopher Ferris <cferris@google.com>
Tue, 5 Aug 2014 22:43:13 +0000 (15:43 -0700)
committerChristopher Ferris <cferris@google.com>
Wed, 6 Aug 2014 18:59:06 +0000 (11:59 -0700)
When calling BacktraceMap::Create(), a NULL pointer is returned if Build
fails. Building twice can cause problems and might leak memory.

Change-Id: I38a4100e534ef15a19883703aa504e795a14b6de

runtime/mem_map.cc

index 6c7ee5b..c281b22 100644 (file)
@@ -135,7 +135,7 @@ static bool CheckOverlapping(uintptr_t begin,
                              uintptr_t end,
                              std::string* error_msg) {
   std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid(), true));
-  if (!map->Build()) {
+  if (map.get() == nullptr) {
     *error_msg = StringPrintf("Failed to build process map");
     return false;
   }
@@ -158,7 +158,7 @@ static bool CheckNonOverlapping(uintptr_t begin,
                                 uintptr_t end,
                                 std::string* error_msg) {
   std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid(), true));
-  if (!map->Build()) {
+  if (map.get() == nullptr) {
     *error_msg = StringPrintf("Failed to build process map");
     return false;
   }