google / sanitizers

AddressSanitizer, ThreadSanitizer, MemorySanitizer
Other
11.41k stars 1.03k forks source link

LSan error "Unmatched call to __lsan_enable()" is incredibly vague #1758

Open mchristoff opened 4 months ago

mchristoff commented 4 months ago

Using LSan's provided interface in lsan_interface.h, we attempted to use the __lsan_enable() call at the beginning of the program to assure that it was turned on if it was turned off by some infrastructure previously. This, however, resulted in this error message: ==2100623==Unmatched call to __lsan_enable(). This error message, however, is very vague. There isn't any official documentation for this API, so this combined with the non-descriptive error message led to a lot of headache.

For one, it isn't obvious this error messages comes out of LSan from a glance. Second, there isn't any description of how the issue could be fixed. If, for instance, it instead said: ==2100623==Unmatched call to __lsan_enable() without corresponding call to __lsan_disable(). or something along those lines, that would be much more descriptive and actually point to a solution. This would also make it clear the error message is coming out of LSan rather than something else.

As a note, the only other indication that there needs to be a matching pair of calls is this comment in lsan_interface.h:

// Allocations made between calls to __lsan_disable() and __lsan_enable() will
// be treated as non-leaks. Disable/enable pairs may be nested.
void SANITIZER_CDECL __lsan_disable(void);
void SANITIZER_CDECL __lsan_enable(void);

Even this, though, isn't concrete and is easy to miss. It would be helpful to add a comment in the lsan_interface.h file that describes this requirement in lieu of documentation.