-
Notifications
You must be signed in to change notification settings - Fork 10
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
GSlice: Cannot allocate memory (with _posix_memalign) #3
Comments
Possibly relevant: $ valgrind --track-origins=yes ./WS/build/test/OcvMatcherTest |
This is related to how how log-malloc is allocating when using posix_memalig. Internaly it is using simple malloc, because I didn't wanted to waste too much memory for the head record and therfore the memory is not really aligned as it might be expected from the app. Unfortunately, I don't have time right now to fix this immediately, but I'm adding it to my todo list... |
posix_memalign implementation here has a bug. it never writes allocated memory address to the resulting pointer address. |
Applications that use cv::fastMalloc to call posix_memalign(&ptr, CV_MALLOC_ALIGN, size) fail during dl_init with:
MEMORY-ERROR: [20699]: GSlice: failed to allocate 1008 bytes (alignment: 1024): Cannot allocate memory
#include <opencv2/core/core.hpp>
int main(int argc, char* argv[]) {
// cv::fastMalloc(1024);
return 0;
}
Reference: https://github.com/opencv/opencv/blob/master/modules/core/src/alloc.cpp
$ LD_PRELOAD=/usr/local/lib/liblog-malloc2.so lldb-8 -- ./WS/build/test/OcvMatcherTest
*** log-malloc trace-fd = 1022 ***
*** log-malloc trace-fd = 1022 ***
*** log-malloc trace-fd = 1022 ***
(lldb) r
...
MEMORY-ERROR: [20871]: GSlice: failed to allocate 1008 bytes (alignment: 1024): Cannot allocate memory
Process 20871 stopped
frame #0: 0x00007fffc25ca428 libc.so.6`__GI_raise(sig=6) at raise.c:54
(lldb) bt
__GI_raise(sig=6) at raise.c:54 frame #1: 0x00007fffc25cc02a libc.so.6
__GI_abort at abort.c:89frame -lunwind missing #2: 0x00007fffbf84a961 libglib-2.0.so.0
___lldb_unnamed_symbol277$$libglib-2.0.so.0 + 273 frame #3: 0x00007fffbf84b406 libglib-2.0.so.0
___lldb_unnamed_symbol282$$libglib-2.0.so.0 + 518frame Invalid log in multithreaded app on Linux #4: 0x00007fffbf84bfba libglib-2.0.so.0
g_slice_alloc + 1594 frame #5: 0x00007fffbf81d74e libglib-2.0.so.0
g_hash_table_new_full + 30frame #6: 0x00007fffbf83e94b libglib-2.0.so.0
___lldb_unnamed_symbol241$$libglib-2.0.so.0 + 75 frame #7: 0x00007ffff7de76ca ld-2.23.so
call_init(l=, argc=1, argv=0x00007fffffffde78, env=0x00007fffffffde88) at dl-init.c:72frame #8: 0x00007ffff7de77db ld-2.23.so
_dl_init at dl-init.c:30 frame #9: 0x00007ffff7de77c5 ld-2.23.so
_dl_init(main_map=0x00007ffff7ffe168, argc=1, argv=0x00007fffffffde78, env=0x00007fffffffde88) at dl-init.c:120frame #10: 0x00007ffff7dd7c6a ld-2.23.so`_dl_start_user + 50
The problem could be related to dl_init of libopencv_core.so.3.4 (walking on thin ice here). For instance, running under G_SLICE=always-malloc, my application (or the reproducer) recurses to failure in cv::fastMalloc (OpenCV 3.4.5, gcc 5.4 and CUDA 8.0 on 16.04) OR (OpenCV 3.4.5, gcc 7.3 without CUDA on 18.04).
(lldb) thread backtrace -c 11 -s 17080
frame #17080: 0x00007ffff6effb8a libopencv_core.so.3.4
cv::fastMalloc(unsigned long) + 90 frame #17081: 0x00007ffff6e6de1d libopencv_core.so.3.4
cv::String::allocate(unsigned long) + 29frame #17082: 0x00007ffff7021759 libopencv_core.so.3.4
cv::format(char const*, ...) + 521 frame #17083: 0x00007ffff6effb8a libopencv_core.so.3.4
cv::fastMalloc(unsigned long) + 90frame #17084: 0x00007ffff6efcb12 libopencv_core.so.3.4
cvRegisterType + 434 frame #17085: 0x00007ffff6e36774 libopencv_core.so.3.4
CvType::CvType(char const*, int ()(void const), void ()(void**), void ()(CvFileStorage, CvFileNode*), void ()(CvFileStorage, char const*, void const*, CvAttrList), void* ()(void const)) + 100frame #17086: 0x00007ffff6e367dd libopencv_core.so.3.4
_GLOBAL__sub_I_persistence_types.cpp + 61 frame #17087: 0x00007ffff7de76ca ld-2.23.so
call_init(l=, argc=7, argv=0x00007fffffffdcb8, env=0x00007fffffffdcf8) at dl-init.c:72frame #17088: 0x00007ffff7de77db ld-2.23.so
_dl_init at dl-init.c:30 frame #17089: 0x00007ffff7de77c5 ld-2.23.so
_dl_init(main_map=0x00007ffff7ffe168, argc=7, argv=0x00007fffffffdcb8, env=0x00007fffffffdcf8) at dl-init.c:120frame #17090: 0x00007ffff7dd7c6a ld-2.23.so`_dl_start_user + 50
The text was updated successfully, but these errors were encountered: