diff --git a/blockchain.go b/blockchain.go index a5c74d6..5f6892d 100644 --- a/blockchain.go +++ b/blockchain.go @@ -254,8 +254,14 @@ func blockchainVerifyEverything() error { } blockKeyOps, err := b.dbGetKeyOps() if err != nil { + if err := b.Close(); err != nil { + panic(err) + } return fmt.Errorf("block %d: cannot get key ops: %v", height, err) } + if err = b.Close(); err != nil { + panic(err) + } Q := QuorumForHeight(height) for keyOpKeyHash, keyOps := range blockKeyOps { if len(keyOps) != Q { @@ -431,6 +437,10 @@ func OpenBlockFile(fileName string) (*Block, error) { return &b, nil } +func (b *Block) Close() error { + return b.db.Close() +} + // Returns an integer value from the _meta table within the block func (b *Block) dbGetMetaInt(key string) (int, error) { var value string diff --git a/p2p.go b/p2p.go index 54915ef..6c51896 100644 --- a/p2p.go +++ b/p2p.go @@ -737,6 +737,7 @@ func (p2pc *p2pConnection) handleBlock(msg StrIfMap) { return } log.Println("Accepted block", blk.Hash, "at height", blk.Height) + blk.Close() } // Connect to a peer. Does everything except starting the handler goroutine.