From 5849bf99362bc702c5d1ee9d197fedac1c374436 Mon Sep 17 00:00:00 2001 From: Anton Tiurin Date: Thu, 11 Jun 2015 21:49:27 +0300 Subject: [PATCH] [MemMap] Fix a data race Signed-off-by: Anton Tiurin --- memmap.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/memmap.go b/memmap.go index 2474a3f..134c67f 100644 --- a/memmap.go +++ b/memmap.go @@ -78,10 +78,11 @@ func (MemMapFs) Name() string { return "MemMapFS" } func (m *MemMapFs) Create(name string) (File, error) { m.lock() - m.getData()[name] = MemFileCreate(name) + file := MemFileCreate(name) + m.getData()[name] = file m.unlock() - m.registerDirs(m.getData()[name]) - return m.getData()[name], nil + m.registerDirs(file) + return file, nil } func (m *MemMapFs) registerDirs(f File) { @@ -139,9 +140,10 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error { return ErrFileExists } else { m.lock() - m.getData()[name] = &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true} + item := &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true} + m.getData()[name] = item m.unlock() - m.registerDirs(m.getData()[name]) + m.registerDirs(item) } return nil }