Crashes in free() on Android/ARM

46 views
Skip to first unread message

Clemens Eisserer

unread,
Aug 25, 2015, 1:17:30 PM8/25/15
to tesseract-ocr
Hi,

I am trying to use Tesseract in a multi-threaded Android application, where we actually would like to OCR multiple separate lines of text in parallel.
However, from time to time the application crashes due to an invalid call to free (4 examples below).
This happens interestingly only on a low-end Android-4.4 device, the Android-5 device I also use for development runs the code fine (however, it has three times the memory).

Here is how I use Tesseract:
- At startup 4 instances of TessBaseAPI are instantiated, as well as a ThreadPoolExecutor with 4 threads
- When processing, 4 separate lines of text are processed, where each TessBaseAPI processes a single line on a separate Thread:

public void run() {
baseApi.setImage(bitmap);
baseApi.getUTF8Text();
}

Here is what I've tried so far:
- Ran all other native code (without tesseract) under valgrind to make sure something else is not corrupting the heap - zero errors are reported
- Made sure a TessBaseAPI-Instance isn't used by multiple threads concurrently

Any further ideas what I could try to track this issue down?

Thank you in advance, Clemens

08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea44  400b0d5d  /system/lib/libc.so (free+12)
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea4c  5f53da6b  /data/app-lib/com.example.cam-1/libtess.so (TWERD::Clear()+60)
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea5c  5f548457  /data/app-lib/com.example.cam-1/libtess.so (TWERD::~TWERD()+8)
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea64  5f54849b  /data/app-lib/com.example.cam-1/libtess.so (WERD_RES::ClearResults()+58)
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea6c  5f548afd  /data/app-lib/com.example.cam-1/libtess.so (WERD_RES_zapper(ELIST_LINK*))
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea74  5f548aa5  /data/app-lib/com.example.cam-1/libtess.so (WERD_RES::~WERD_RES()+8)
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea7c  5f548b07  /data/app-lib/com.example.cam-1/libtess.so (WERD_RES_zapper(ELIST_LINK*)+10)
08-25 17:26:34.049      226-226/? I/DEBUG﹕ 6286ea84  5f5533a1  /data/app-lib/com.example.cam-1/libtess.so (ELIST::internal_clear(void (*)(ELIST_LINK*))+24)


08-25 17:14:32.999      226-226/? I/DEBUG﹕ #08  pc 0000dd5b  /system/lib/libc.so (free+10)
08-25 17:14:32.999      226-226/? I/DEBUG﹕ #09  pc 000b839f  /data/app-lib/com.example.cam-1/libtess.so (ELIST::internal_clear(void (*)(ELIST_LINK*))+22)
08-25 17:14:32.999      226-226/? I/DEBUG﹕ #10  pc 000acb0d  /data/app-lib/com.example.cam-1/libtess.so (GENERIC_2D_ARRAY<BLOB_CHOICE_LIST*>::delete_matrix_pointers()+40)


08-25 16:53:14.709      226-226/? I/DEBUG﹕ 6209993c  400b0d5d  /system/lib/libc.so (free+12)
08-25 16:53:14.709      226-226/? I/DEBUG﹕ 62099940  5f671450  /data/app-lib/com.example.cam-2/libtess.so
08-25 16:53:14.709      226-226/? I/DEBUG﹕ 62099944  5f52963b  /data/app-lib/com.example.cam-2/libtess.so (_TessFunctionResultCallback_0_2<false, bool, int const&, int const&>::~_TessFunctionResultCallback_0_2()+18)
08-25 16:53:14.709      226-226/? I/DEBUG﹕ 62099948  6209996c  [stack:23160]
08-25 16:53:14.709      226-226/? I/DEBUG﹕ 6209994c  5f5128ef  /data/app-lib/com.example.cam-2/libtess.so (GenericVector<int>::clear()+82)


08-25 13:27:54.401      226-226/? I/DEBUG﹕ #00  pc 000118bc  /system/lib/libc.so (dlfree+1191)
08-25 13:27:54.401      226-226/? I/DEBUG﹕ #01  pc 0000dd5b  /system/lib/libc.so (free+10)
08-25 13:27:54.401      226-226/? I/DEBUG﹕ #02  pc 000b839f  /data/app-lib/com.example.cam-2/libtess.so (ELIST::internal_clear(void (*)(ELIST_LINK*))+22)
08-25 13:27:54.401      226-226/? I/DEBUG﹕ #03  pc 000acb0d  /data/app-lib/com.example.cam-2/libtess.so (GENERIC_2D_ARRAY<BLOB_CHOICE_LIST*>::delete_matrix_pointers()+40)

Clemens Eisserer

unread,
Aug 26, 2015, 9:18:32 AM8/26/15
to tesseract-ocr
Mea culpa, my valgrind testcase did not test all possible code-paths, and indeed some other code did some nasty things due to a not properly handled error condition.
With this error fixed, the application is rock-solid and also valgrind seems to be happy :)
 
Thanks & best regards, Clemens
Reply all
Reply to author
Forward
0 new messages