profiling: Do not install hook if Client init fails.

Change-Id: Ia26e12701d8bfc4bc8990545c0d74fb7cd2d0fd1
diff --git a/src/profiling/memory/client.h b/src/profiling/memory/client.h
index c9595c2..3b6fe45 100644
--- a/src/profiling/memory/client.h
+++ b/src/profiling/memory/client.h
@@ -142,6 +142,7 @@
   void Shutdown();
 
   ClientConfiguration client_config_for_testing() { return client_config_; }
+  bool inited() { return inited_; }
 
  private:
   size_t ShouldSampleAlloc(uint64_t alloc_size,
diff --git a/src/profiling/memory/malloc_hooks.cc b/src/profiling/memory/malloc_hooks.cc
index cdbe5e5..38fab05 100644
--- a/src/profiling/memory/malloc_hooks.cc
+++ b/src/profiling/memory/malloc_hooks.cc
@@ -111,10 +111,13 @@
   g_dispatch.store(malloc_dispatch, write_order);
   // This can store a nullptr, so we have to check in the hooks below to avoid
   // segfaulting in that case.
-  g_client.store(
+  std::unique_ptr<perfetto::profiling::Client> client(
       new (std::nothrow) perfetto::profiling::Client(
-          perfetto::profiling::kHeapprofdSocketFile, kNumConnections),
-      write_order);
+          perfetto::profiling::kHeapprofdSocketFile, kNumConnections));
+  if (!client || !client->inited())
+    return false;
+
+  g_client.store(client.release());
   return true;
 }