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:
Tommi Virtanen 2015-05-31 15:47:36 -07:00 committed by Jeromy
parent 694abdeea3
commit c0ec377269

View File

@ -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 {