Conversation
|
Wow, not bad!
That might be because the load/store sequence is broken, but i'm not sure. must perform a I'm fine with this, we can just say it's a problem and we're fine with it for now. |
|
|
||
| var iter = self.contents.iterator(); | ||
| while (iter.next()) |entry| { | ||
| arr.contents.putAssumeCapacity(try arr.allocator.dupe(u8, entry.key_ptr.*), try entry.value_ptr.clone()); |
There was a problem hiding this comment.
Potential memory leak here when arr.allocator.dupe fails to clone the key.
You gotta construct both locally first and errdefer-free them, then put the key/value pair
There was a problem hiding this comment.
putAssumeCapacity can't fail. You would just need to errdefer duped_key.deinit() before adding the key and value to arr
There was a problem hiding this comment.
even then, it's a bug right now :)
i'd just use two errdefers, and make it so that future expansions dont have to think about the cleanup.
the compiler won't emit the second errdefer anyways until there's an error
|
|
||
| var iter = self.contents.iterator(); | ||
| while (iter.next()) |entry| { | ||
| arr.contents.putAssumeCapacity(try arr.allocator.dupe(u8, entry.key_ptr.*), try entry.value_ptr.clone()); |
There was a problem hiding this comment.
| arr.contents.putAssumeCapacity(try arr.allocator.dupe(u8, entry.key_ptr.*), try entry.value_ptr.clone()); | |
| const duped_key = try arr.allocator.dupe(u8, entry.key_ptr.*); | |
| errdefer arr.allocator.free(duped_key); | |
| arr.contents.putAssumeCapacity(duped_key, try entry.value_ptr.clone()); |
uses
var a = [ .foo = bar ];syntax. Nested structs give a segfault for some reason though. #39