[#1664] write-cache: Fix panic on Delete
operation
If an object is found in the Write-cache and is placed at the end of the in-memory cache, the memory counter update operation tries to dereference the index that is out of the sliced array. Moreover, even if panic does not appear, the counter is updated with the wrong value. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
81684b6f04
commit
da2975a2f9
2 changed files with 2 additions and 1 deletions
|
@ -8,6 +8,7 @@ Changelog for NeoFS Node
|
|||
### Changed
|
||||
|
||||
### Fixed
|
||||
- Panic on write-cache's `Delete` operation (#1664)
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -26,9 +26,9 @@ func (c *cache) Delete(addr oid.Address) error {
|
|||
c.mtx.Lock()
|
||||
for i := range c.mem {
|
||||
if saddr == c.mem[i].addr {
|
||||
c.curMemSize -= uint64(len(c.mem[i].data))
|
||||
copy(c.mem[i:], c.mem[i+1:])
|
||||
c.mem = c.mem[:len(c.mem)-1]
|
||||
c.curMemSize -= uint64(len(c.mem[i].data))
|
||||
c.mtx.Unlock()
|
||||
storagelog.Write(c.log, storagelog.AddressField(saddr), storagelog.OpField("in-mem DELETE"))
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue