@@ -397,12 +397,7 @@ pub const JournalInner = struct {
397397 pub fn deinit (self : * JournalInner ) void {
398398 self .evm_state .deinit ();
399399 self .transient_storage .deinit ();
400- // Free heap-allocated topic slices before freeing the log list
401- for (self .logs .items ) | log | {
402- if (log .topics .len > 0 ) {
403- alloc_mod .get ().free (@constCast (log .topics ));
404- }
405- }
400+ for (self .logs .items ) | log | log .deinit (alloc_mod .get ());
406401 self .logs .deinit (alloc_mod .get ());
407402 self .journal .deinit (alloc_mod .get ());
408403 self .warm_addresses .deinit ();
@@ -441,12 +436,8 @@ pub const JournalInner = struct {
441436 self .journal .clearRetainingCapacity ();
442437 self .warm_addresses .clearCoinbaseAndAccessList ();
443438 self .transaction_id += 1 ;
444- // Free heap-allocated topic slices (in case takeLogs() was not called)
445- for (self .logs .items ) | log | {
446- if (log .topics .len > 0 ) {
447- alloc_mod .get ().free (@constCast (log .topics ));
448- }
449- }
439+ // Free heap-allocated data/topics (in case takeLogs() was not called — e.g. failed tx)
440+ for (self .logs .items ) | log | log .deinit (alloc_mod .get ());
450441 self .logs .clearRetainingCapacity ();
451442 }
452443
@@ -463,12 +454,8 @@ pub const JournalInner = struct {
463454 }
464455
465456 self .transient_storage .clearRetainingCapacity ();
466- // Free heap-allocated topic slices before clearing the log list
467- for (self .logs .items ) | log | {
468- if (log .topics .len > 0 ) {
469- alloc_mod .get ().free (@constCast (log .topics ));
470- }
471- }
457+ // Free heap-allocated data/topics before clearing the log list
458+ for (self .logs .items ) | log | log .deinit (alloc_mod .get ());
472459 self .logs .clearRetainingCapacity ();
473460 self .transaction_id += 1 ;
474461 self .warm_addresses .clearCoinbaseAndAccessList ();
@@ -483,12 +470,7 @@ pub const JournalInner = struct {
483470
484471 const evm_state = self .evm_state ;
485472 self .evm_state = state .EvmState .init (alloc_mod .get ());
486- // Free heap-allocated topic slices before clearing the log list.
487- for (self .logs .items ) | log | {
488- if (log .topics .len > 0 ) {
489- alloc_mod .get ().free (@constCast (log .topics ));
490- }
491- }
473+ for (self .logs .items ) | log | log .deinit (alloc_mod .get ());
492474 self .logs .clearRetainingCapacity ();
493475 self .transient_storage .clearRetainingCapacity ();
494476 self .journal .clearRetainingCapacity ();
@@ -722,6 +704,8 @@ pub const JournalInner = struct {
722704 /// Reverts all changes to evm_state until given checkpoint.
723705 pub fn checkpointRevert (self : * JournalInner , checkpoint : JournalCheckpoint ) void {
724706 const is_spurious_dragon_enabled = primitives .isEnabledIn (self .spec , .spurious_dragon );
707+ // Free heap-allocated data/topics of logs being discarded by this revert.
708+ for (self .logs .items [checkpoint .log_i .. ]) | log | log .deinit (alloc_mod .get ());
725709 self .logs .shrinkRetainingCapacity (checkpoint .log_i );
726710
727711 // iterate over last N journals sets and revert our global evm_state
0 commit comments