jlaurens / synctex

Synchronization for TeX
MIT License
64 stars 19 forks source link

Mem Leak with iterators #55

Closed stloeffler closed 1 year ago

stloeffler commented 1 year ago

To reproduce, compile with Leak Sanitizer and run build/synctex view -i 17:0:sync.tex -o synctex\ test\ files/texworks/sync.pdf

From synctex_iterator_new_display, _synctex_display_query_v2 is called, where new handles are created (synctex_parser.c#L7443) and existing/previous handles are assigned as children of the newly created handle (synctex_parser.c#L7449). However, the parent of the newly assigned child is never set. Consequently, the algorithm in _synctex_free_handle (synctex_parser.c#L929) fails to properly free all nodes (it seems to go down the tree successfully, but cannot go up anymore as the information on the parent nodes is missing).

Presumably, the parent information should be set correctly, but this is complicated by the case where matches span several pages (and setting the parent information incorrectly can crash the program). Alternatively, _synctex_free_handle can be modified to enforce proper parent information "on the way down" to ensure the tree can be properly fully.