From 54dffda2b6f967d216b59fcbda116c74b07c4990 Mon Sep 17 00:00:00 2001 From: Jan Ziak <0xe2.0x9a.0x9b@gmail.com> Date: Tue, 19 Mar 2013 22:17:39 +0100 Subject: runtime: prevent garbage collection during hashmap insertion Inserting a key-value pair into a hashmap storing keys or values indirectly can cause the garbage collector to find the hashmap in an inconsistent state. Fixes #5074. R=golang-dev, minux.ma, rsc CC=golang-dev https://golang.org/cl/7913043 --- src/pkg/runtime/hashmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/pkg/runtime/hashmap.c') diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c index 37111daa90..dc5dfb82f5 100644 --- a/src/pkg/runtime/hashmap.c +++ b/src/pkg/runtime/hashmap.c @@ -1016,10 +1016,12 @@ runtime·mapassign(MapType *t, Hmap *h, byte *ak, byte *av) res = nil; hit = hash_insert(t, h, ak, (void**)&res); if(!hit) { + // Need to pass dogc=0 to runtime·mallocgc because the garbage collector + // is assuming that all hashmaps are in a consistent state. if(h->flag & IndirectKey) - *(void**)res = runtime·mal(t->key->size); + *(void**)res = runtime·mallocgc(t->key->size, 0, 0, 1); if(h->flag & IndirectVal) - *(void**)(res+h->valoff) = runtime·mal(t->elem->size); + *(void**)(res+h->valoff) = runtime·mallocgc(t->elem->size, 0, 0, 1); } t->key->alg->copy(t->key->size, hash_keyptr(h, res), ak); t->elem->alg->copy(t->elem->size, hash_valptr(h, res), av); -- cgit v1.3-5-g9baa