@@ -351,14 +351,16 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
351351 // Commit block.txs.
352352 // ........................................................................
353353
354- // This must not be a reference to the shared pointer, as otherwise the
355- // shared_ptr may be taken out of scope before the tx write completes.
356- // set_code() uses weak references to many elements of the transaction ref.
357- const auto txs_ptr = block->transactions_ptr ();
358- const auto size = block->serialized_size (true );
354+ // IMPORTANT: ~block() releases all memory for parts of itself, as a
355+ // consequence of the custom memory allocator. Therefore, while shared_ptr
356+ // to an element of the block would normally be valid after ~block(), the
357+ // object pointed to will have been deallocated by ~block(). Therefore a
358+ // reference to `block` must be passed to set_code (i.e. not a copy of or
359+ // reference to `lock->transactions_ptr()`.
359360
360361 // This invokes set_strong when checked.
361- if (const auto code = query.set_code (*txs_ptr, link, size, checked))
362+ const auto bytes = block->serialized_size (true );
363+ if (const auto code = query.set_code (*block, link, checked, bytes))
362364 {
363365 LOGF (" Failure storing block [" << encode_hash (hash) << " :" << height
364366 << " ] from [" << authority () << " ] " << code.message ());
@@ -376,7 +378,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
376378 notify (ec, chase::checked, height);
377379 fire (events::block_archived, height);
378380
379- count (size );
381+ count (bytes );
380382 map_->erase (it);
381383 if (is_idle ())
382384 {
0 commit comments