-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory issues in ScrollView::MessageReceiver #3872
Conversation
@rmast Could you please check whether this PR fixes the issue you were seeing. I didn't try to reproduce the problem, only diagnosed the problem by looking into source code. |
I still get an error when running with valgrind:
|
With this additional change Tesseract no longer crashes:
I still don't know whether memory leaks remain. |
I’m now running a build starting with the 2 commits from Povilas and adapted with two changes from Stefan. (One from this thread, one from a new commit on the main)
|
There remain two direct leaks (48 + 16 bytes) and an indirect leak (4 bytes). They are shown when I build |
waiting_for_events takes ownership of the passed event which is later deleted. Since we use unique_ptr::get() to acquire the pointer, we cause double free: one free happens in the code path where the event from waiting_for_events goes and the other free happens in unique_ptr destructor. The fix is to move ownership out of unique_ptr by unique_ptr::release(). Fixes: tesseract-ocr#3869 Fixes: 37b3374
The current usage of waiting_for_events is taking ownership of SVEvent pointer from a unique_ptr. This is error prone as all code paths using waiting_for_events need to ensure deletion. We fix it by using unique_ptr in waiting_for_events and all dependent code paths.
bd7e57b
to
0107687
Compare
@stweil I couldn't reproduce the problem and looking into code this crash seems to be something different than what the initial two commits fix. Anyway, I have converted |
This new run, with only Povilas’ branch with 3 force pushed commits did complete without a core dump.
tesseract -c invert_threshold=0.9 --dpi 300 -l Latin -c textord_debug_tabfind=1 -c textord_debug_bugs=1 -c debug_noise_removal=1 -c textord_show_final_rows=1 -c textord_show_final_blobs=1 -c textord_show_initial_rows=1 -c textord_debug_blob=1 -c textord_oldbl_debug=1 -c textord_debug_baselines=1 -c textord_test_mode=1 -c classify_debug_level=1 -c dawg_debug_level=1 -c wordrec_debug_level=1 -c segsearch_debug_level=1 -c wordrec_display_segmentations=1 -c bidi_debug=1 -c debug_noise_removal=1 -c paragraph_debug_level=1 175789293-f39ddfdb-6f3e-4598-8d16-80a1f4a88b36.jpg output90
|
Thanks @rmast for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My test also passes without problems, and there remains no memory leak.
Thank you very much for this contribution!
Nice work, thanks. |
This PR fixes memory issues that caused #3869. The first commit fixes the actual bug (
unique_ptr::release()
should be used instead ofunique_ptr::get()
). The second fixes the underlying problem of using plain pointers that caused the bug in the first place.Fixes #3869.
Supersedes #3870
FYI @rmast @stweil.