diff options
| author | Carl Shapiro <cshapiro@google.com> | 2013-12-06 14:40:45 -0800 |
|---|---|---|
| committer | Carl Shapiro <cshapiro@google.com> | 2013-12-06 14:40:45 -0800 |
| commit | 76c54c11935121d1c8f4158f900366d68f9a76d8 (patch) | |
| tree | 69bbe18a27f0421639df72c4d1b5fef783950945 /src/pkg/runtime/malloc.goc | |
| parent | a5cc5bab5a8ead995d5eb51ee0991635eeab15ed (diff) | |
| download | go-76c54c11935121d1c8f4158f900366d68f9a76d8.tar.xz | |
runtime: add GODEBUG option for an electric fence like heap mode
When enabled this new debugging mode will allocate objects on
their own page and never recycle memory addresses. This is an
essential tool to root cause a broad class of heap corruption.
R=golang-dev, dave, daniel.morsing, dvyukov, rsc, iant, cshapiro
CC=golang-dev
https://golang.org/cl/22060046
Diffstat (limited to 'src/pkg/runtime/malloc.goc')
| -rw-r--r-- | src/pkg/runtime/malloc.goc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index 46d6450c06..cd124f0f71 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -58,7 +58,7 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag) size += sizeof(uintptr); c = m->mcache; - if(size <= MaxSmallSize) { + if(!runtime·debug.efence && size <= MaxSmallSize) { // Allocate from mcache free lists. // Inlined version of SizeToClass(). if(size <= 1024-8) @@ -196,7 +196,10 @@ runtime·free(void *v) // they might coalesce v into other spans and change the bitmap further. runtime·markfreed(v, size); runtime·unmarkspan(v, 1<<PageShift); - runtime·MHeap_Free(&runtime·mheap, s, 1); + if(runtime·debug.efence) + runtime·SysFree((void*)(s->start<<PageShift), size, &mstats.heap_sys); + else + runtime·MHeap_Free(&runtime·mheap, s, 1); c->local_nlargefree++; c->local_largefree += size; } else { |
