lsan report a leak when using vtkRenderWindow with mesa without a vtkRenderWindowInteractor
lsan reports a leak when calling vtkRenderWindow::Render() without using a vtkRenderWindowInteractor, only on mesa.
Excerpt code to reproduce (full code below):
vtkNew<vtkRenderWindow> renderWindow;
renderWindow.Render();
Stesp to reproduce:
- Build VTK
- Build this slightly modified CylinderExample with
-fsanitize=address
cxx flag. - run with mesa:
__GLX_VENDOR_LIBRARY_NAME=mesa LIBGL_ALWAYS_SOFTWARE=1 ./CylinderExample
[glow@arch ~/tmp/CylinderExample/build]$ __GLX_VENDOR_LIBRARY_NAME=mesa LIBGL_ALWAYS_SOFTWARE=1 ./CylinderExample
=================================================================
==518583==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 128 byte(s) in 1 object(s) allocated from:
#0 0x7f277a22a1b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
#1 0x7f276973a5ea (<unknown module>)
Direct leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x7f277a22b811 in operator new(unsigned long) /usr/src/debug/gcc/libsanitizer/asan/asan_new_delete.cpp:99
#1 0x7f27697194bd (<unknown module>)
Indirect leak of 56 byte(s) in 1 object(s) allocated from:
#0 0x7f277a229fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x7f276a7d11e8 (/usr/lib/libasan.so.6.0.0+0x3eb1e8)
Indirect leak of 56 byte(s) in 1 object(s) allocated from:
#0 0x7f277a229fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x7f276a7d11d0 (/usr/lib/libasan.so.6.0.0+0x3eb1d0)
SUMMARY: AddressSanitizer: 304 byte(s) leaked in 4 allocation(s).
Notes:
- Using a vtkRenderWindowInteractor prevents/hide the leak. See the relevant part in CylinderExample.
- Comenting out the whole vtkRenderWindow::Render() method also prevents the leak, so it is not in the X initialization stack but in the actual rendering code that the leak occurs.
- For some reason, LSAN does not provide the callstack. Using
fast_unwind_on_malloc=0
is supposed to work around that but this LSAN flags hangs when using mesa. - The allocation probably occurs in mesa stack, as leaks in VTK are correctly reported by LSAN in my tests. This means that building mesa in debug may be a way forward to isolate the issue.
- Switching to nvidia prevents/hides the leak
I spent multiples hours trying to figure this one out but am on my wits ends. In any case, this is probably either a leak in mesa or a false positive, but the fact that using a vtkRenderWindorInteractor hides it shows that maybe there is something that VTK can do.
I will just hide the leak in my own CI. This issue is for information and if someone else is impacted.
Edited by Mathieu Westphal (Kitware)