Fix accessing to layer without lock

There was a possibility to panic due to such behavior:
attempted to update last-writer in lockfile without the write lock

Fixes: https://github.com/containers/storage/issues/1324

Signed-off-by: Mikhail Khachayants <tyler92@inbox.ru>
This commit is contained in:
Mikhail Khachayants 2022-09-16 10:25:44 +03:00 committed by tyler92
parent 8a581aac3b
commit e35b061b85
1 changed files with 4 additions and 0 deletions

View File

@ -563,6 +563,8 @@ func (s *store) newLayerStore(rundir string, layerdir string, driver drivers.Dri
uidMap: copyIDMap(s.uidMap),
gidMap: copyIDMap(s.gidMap),
}
rlstore.Lock()
defer rlstore.Unlock()
if err := rlstore.Load(); err != nil {
return nil, err
}
@ -584,6 +586,8 @@ func newROLayerStore(rundir string, layerdir string, driver drivers.Driver) (ROL
bymount: make(map[string]*Layer),
byname: make(map[string]*Layer),
}
rlstore.RLock()
defer rlstore.Unlock()
if err := rlstore.Load(); err != nil {
return nil, err
}