From c0ec3772698fd7eed226e273a46386bc2b2d8308 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Sun, 31 May 2015 15:47:36 -0700 Subject: [PATCH] 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 --- pin/indirect.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pin/indirect.go b/pin/indirect.go index dca99600f..e5ed5dcb6 100644 --- a/pin/indirect.go +++ b/pin/indirect.go @@ -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 {