@@ -978,6 +978,8 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
978978func (bc * BlockChain ) writeHeadBlock (block * types.Block ) {
979979 // Add the block to the canonical chain number scheme and mark as the head
980980 batch := bc .db .NewBatch ()
981+ defer batch .Close ()
982+
981983 rawdb .WriteHeadHeaderHash (batch , block .Hash ())
982984 rawdb .WriteHeadFastBlockHash (batch , block .Hash ())
983985 rawdb .WriteCanonicalHash (batch , block .Hash (), block .NumberU64 ())
@@ -1437,6 +1439,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
14371439 // Note all the components of block(td, hash->number map, header, body, receipts)
14381440 // should be written atomically. BlockBatch is used for containing all components.
14391441 blockBatch := bc .db .NewBatch ()
1442+ defer blockBatch .Close ()
14401443 rawdb .WriteTd (blockBatch , block .Hash (), block .NumberU64 (), externTd )
14411444 rawdb .WriteBlock (blockBatch , block )
14421445 rawdb .WriteReceipts (blockBatch , block .Hash (), block .NumberU64 (), receipts )
@@ -2286,6 +2289,8 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Header) error {
22862289 // Delete useless indexes right now which includes the non-canonical
22872290 // transaction indexes, canonical chain indexes which above the head.
22882291 batch := bc .db .NewBatch ()
2292+ defer batch .Close ()
2293+
22892294 for _ , tx := range types .HashDifference (deletedTxs , rebirthTxs ) {
22902295 rawdb .DeleteTxLookupEntry (batch , tx )
22912296 }
0 commit comments