Closed kevinmehall closed 7 years ago
@kevinmehall Good catch. I like the idea of reconsidering the use of macros. I'll merge this, because leaking is an improvement over use-after-free, and then I'll look into a more permanent fix.
Merged on the command-line, because the changes from #9 required an additional unsafe
block.
The
from_libusb
functions turn a raw pointer into a struct with safe methods and destructors that dereference the pointer. These functions are currently misused by the tests to violate memory safety in "safe" code -- the test_helpers macros return structures containing pointers to memory that was freed when theVec
goes out of scope within the macro.Since there isn't a good way to move the scope of the
Vec
out to the function level besides manually expanding the macros, I made the macros simply leak theVec
. It may be better to reconsider the use of macros here, and construct the test data statically or in the scope of the test function.The consequences of the use-after-free are masked by jemalloc, but show up as segfaults and in valgrind when compiled with `alloc_system: