Prevent overflow.

This commit is contained in:
Nuno Cruces
2024-10-28 13:25:09 +00:00
parent 96074b24bf
commit df4e144e89
3 changed files with 13 additions and 17 deletions

View File

@@ -78,19 +78,15 @@ type memDB struct {
// +checklocks:dataMtx
data []*[sectorSize]byte
// +checklocks:dataMtx
size int64
// +checklocks:lockMtx
shared int32
// +checklocks:lockMtx
reserved bool
// +checklocks:lockMtx
pending bool
// +checklocks:memoryMtx
refs int
refs int32
shared int32 // +checklocks:lockMtx
pending bool // +checklocks:lockMtx
reserved bool // +checklocks:lockMtx
lockMtx sync.Mutex
dataMtx sync.RWMutex
@@ -253,12 +249,12 @@ func (m *memFile) Unlock(lock vfs.LockLevel) error {
m.lockMtx.Lock()
defer m.lockMtx.Unlock()
if m.pending && m.lock >= vfs.LOCK_PENDING {
m.pending = false
}
if m.reserved && m.lock >= vfs.LOCK_RESERVED {
if m.lock >= vfs.LOCK_RESERVED {
m.reserved = false
}
if m.lock >= vfs.LOCK_PENDING {
m.pending = false
}
if lock < vfs.LOCK_SHARED {
m.shared--
}

View File

@@ -55,7 +55,7 @@ type vfsShm struct {
regions []*util.MappedRegion
readOnly bool
blocking bool
sync.Mutex
barrier sync.Mutex
}
func (s *vfsShm) shmOpen() _ErrorCode {
@@ -202,9 +202,9 @@ func (s *vfsShm) shmUnmap(delete bool) {
}
func (s *vfsShm) shmBarrier() {
s.Lock()
s.barrier.Lock()
//lint:ignore SA2001 memory barrier.
s.Unlock()
s.barrier.Unlock()
}
func (s *vfsShm) shmEnableBlocking(block bool) {

View File

@@ -224,7 +224,7 @@ func (s *vfsShm) shmLock(offset, n int32, flags _ShmFlag) _ErrorCode {
if s.lock[i] {
panic(util.AssertErr())
}
if s.vfsShmFile.lock[i] < 0 {
if s.vfsShmFile.lock[i]+1 <= 0 {
return _BUSY
}
}