1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

fix(core) check nil for _all_ owned resources

since construction can fail, and construction is non-trivial, it's
probably safer to never assume resource exists.

cc @jbenet @whyrusleeping
This commit is contained in:
Brian Tiger Chow
2015-02-06 11:22:13 -07:00
parent bbcb670ef2
commit 8558838d00

View File

@ -280,17 +280,16 @@ func (n *IpfsNode) teardown() error {
log.Debug("core is shutting down...")
// owned objects are closed in this teardown to ensure that they're closed
// regardless of which constructor was used to add them to the node.
closers := []io.Closer{
n.Blocks,
n.Exchange,
n.Repo,
}
var closers []io.Closer
addCloser := func(c io.Closer) { // use when field may be nil
if c != nil {
closers = append(closers, c)
}
}
addCloser(n.Blocks)
addCloser(n.Exchange)
addCloser(n.Repo)
addCloser(n.Bootstrapper)
if dht, ok := n.Routing.(*dht.IpfsDHT); ok {
addCloser(dht)