mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 05:52:20 +08:00
pin: Guard against callers causing refcount underflow
This used to lead to large refcount numbers, causing Flush to create a lot of IPFS objects, and merkledag to consume tens of gigabytes of RAM. License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -57,6 +57,10 @@ func (i *indirectPin) Increment(k key.Key) {
|
||||
}
|
||||
|
||||
func (i *indirectPin) Decrement(k key.Key) {
|
||||
if i.refCounts[k] == 0 {
|
||||
log.Warningf("pinning: bad call: asked to unpin nonexistent indirect key: %v", k)
|
||||
return
|
||||
}
|
||||
c := i.refCounts[k] - 1
|
||||
i.refCounts[k] = c
|
||||
if c <= 0 {
|
||||
|
Reference in New Issue
Block a user