File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -513,15 +513,26 @@ pub fn getInfo(self: *Self, allocator: std.mem.Allocator) !IndexInfo {
513
513
defer self .releaseSegments (& snapshot ); // FIXME this possibly deletes orphaned segments, do it in a separate thread
514
514
515
515
var attributes : std .StringHashMapUnmanaged (u64 ) = .{};
516
- errdefer attributes .deinit (allocator );
516
+ errdefer {
517
+ var iter = attributes .iterator ();
518
+ while (iter .next ()) | e | {
519
+ allocator .free (e .key_ptr .* );
520
+ }
521
+ attributes .deinit (allocator );
522
+ }
517
523
518
524
var version : u64 = 0 ;
519
525
inline for (segment_lists ) | n | {
520
526
const segments = @field (snapshot , n );
521
527
for (segments .value .nodes .items ) | node | {
522
528
var iter = node .value .attributes .iterator ();
523
529
while (iter .next ()) | entry | {
524
- try attributes .put (allocator , entry .key_ptr .* , entry .value_ptr .* );
530
+ const result = try attributes .getOrPut (allocator , entry .key_ptr .* );
531
+ if (! result .found_existing ) {
532
+ errdefer attributes .removeByPtr (entry .key_ptr );
533
+ result .key_ptr .* = try allocator .dupe (u8 , entry .key_ptr .* );
534
+ }
535
+ result .value_ptr .* = entry .value_ptr .* ;
525
536
}
526
537
std .debug .assert (node .value .info .version > version );
527
538
version = node .value .info .version ;
You can’t perform that action at this time.
0 commit comments