ashvardanian / StringZilla

Up to 10x faster strings for C, C++, Python, Rust, and Swift, leveraging NEON, AVX2, AVX-512, and SWAR to accelerate search, sort, edit distances, alignment scores, etc 🦖
https://ashvardanian.com/posts/stringzilla/
Apache License 2.0
2.05k stars 66 forks source link

Fix: leaks and semantics, testing for memory leaks #64

Closed kmapb closed 8 months ago

kmapb commented 8 months ago

Writing some leak-checking found a few bugs and correctness issues.

sz_string_init_from would sometimes leave a residue of noise in the space field of the new string. Lightly refactor to share some of the logic so it is easier to see that all four fields are set for both shapes of string.

The copied code in move constructor and assignment shared some issues: the target for the move didn't actually get initialized with the values of the source. For the case of move assignment where the target already held values, we need to release the associated memory.

I'm happy with the test code for this; while this is probably not a complete inventory of memory leaks, we have an easy way to add tests for new ones we encounter.

ashvardanian commented 8 months ago

Thank you for the contribution, @kmapb! Will merge it in the morning, together with the remaining constructors.