summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2014-04-12 18:07:11 -0700
committerAliaksey Kandratsenka <alk@tut.by>2014-04-12 18:08:46 -0700
commit802fdb739e7aabcb15443030842a2137a5559338 (patch)
tree93ef89e5e1423c8c35717473b26daf999d6d6404
parent6b83516adefcf0806825f6dba2eb2232615d744b (diff)
downloadgperftools-802fdb739e7aabcb15443030842a2137a5559338.tar.gz
issue-610: use TCMallocGetenvSafe from inside malloc
Instead of plain getenv. So that windows getenv implementation that may call malloc does not deadlock.
-rw-r--r--src/common.cc3
-rw-r--r--src/thread_cache.cc8
2 files changed, 7 insertions, 4 deletions
diff --git a/src/common.cc b/src/common.cc
index 8269fb3..3b66afe 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -36,6 +36,7 @@
#include "common.h"
#include "system-alloc.h"
#include "base/spinlock.h"
+#include "getenv_safe.h" // TCMallocGetenvSafe
namespace tcmalloc {
@@ -51,7 +52,7 @@ static const int32 kDefaultTransferNumObjecs = 32768;
static inline void InitTCMallocTransferNumObjects()
{
if (UNLIKELY(FLAGS_tcmalloc_transfer_num_objects == 0)) {
- const char *envval = getenv("TCMALLOC_TRANSFER_NUM_OBJ");
+ const char *envval = TCMallocGetenvSafe("TCMALLOC_TRANSFER_NUM_OBJ");
FLAGS_tcmalloc_transfer_num_objects = !envval ? kDefaultTransferNumObjecs :
strtol(envval, NULL, 10);
}
diff --git a/src/thread_cache.cc b/src/thread_cache.cc
index eabff40..b98fbee 100644
--- a/src/thread_cache.cc
+++ b/src/thread_cache.cc
@@ -38,6 +38,7 @@
#include <algorithm> // for max, min
#include "base/commandlineflags.h" // for SpinLockHolder
#include "base/spinlock.h" // for SpinLockHolder
+#include "getenv_safe.h" // for TCMallocGetenvSafe
#include "central_freelist.h" // for CentralFreeListPadded
#include "maybe_threads.h"
@@ -313,9 +314,10 @@ int ThreadCache::GetSamplePeriod() {
void ThreadCache::InitModule() {
SpinLockHolder h(Static::pageheap_lock());
if (!phinited) {
- set_overall_thread_cache_size(
- EnvToInt64("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES",
- kDefaultOverallThreadCacheSize));
+ const char *tcb = TCMallocGetenvSafe("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES");
+ if (tcb) {
+ set_overall_thread_cache_size(strtoll(tcb, NULL, 10));
+ }
Static::InitStaticVars();
threadcache_allocator.Init();
phinited = 1;