From da2975a2f95de8f067cd91a4b354bf735c52e48d Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 9 Aug 2022 15:30:40 +0300 Subject: [PATCH] [#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 --- CHANGELOG.md | 1 + pkg/local_object_storage/writecache/delete.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07321562..a5f7227e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Changelog for NeoFS Node ### Changed ### Fixed +- Panic on write-cache's `Delete` operation (#1664) ### Removed diff --git a/pkg/local_object_storage/writecache/delete.go b/pkg/local_object_storage/writecache/delete.go index 4302e16e..61973c6f 100644 --- a/pkg/local_object_storage/writecache/delete.go +++ b/pkg/local_object_storage/writecache/delete.go @@ -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