Skip to content
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

server/motion_processor.cpp: fix crash by freeing cv::Mat the right way #715

Conversation

andrey-utkin
Copy link
Contributor

This happens when schedule changes from 'M' to 'C'.

This is how it looks in the logs:

 I(1/software): motion_blend_radio is set to 15:1
 I(1/software): motion_debug is set to 0
 I(1/software): Motion detected
 E(): Got connection, but failed to accept
 I(1/software): Switching to new recording schedule 'continuous'
 BUG: Segment violation at 0x0000000000000366
 Call trace:
 [0x000055db84eb8d5b]  @ /usr/sbin/bc-server
 [0x00007f9949977320]  @ /lib/x86_64-linux-gnu/libc.so.6
 [0x00007f994a5c77e9] _ZN2cv3Mat7releaseEv+0x00000000 @ /lib/x86_64-linux-gnu/libopencv_core.so.406
 [0x000055db84eb8ee4]  @ /usr/sbin/bc-server
 [0x000055db84ebc2d6]  @ /usr/sbin/bc-server
 [0x000055db84ebc8dd]  @ /usr/sbin/bc-server
 [0x00007f99499cea94]  @ /lib/x86_64-linux-gnu/libc.so.6
 [0x00007f9949a5ba34] __clone+0x00000000 @ /lib/x86_64-linux-gnu/libc.so.6

This is how it looks in the debugger:

 #0  0x00007f994a5c77e9 in cv::Mat::release() () from /lib/x86_64-linux-gnu/libopencv_core.so.406
 #1  0x000055db84eb8ee4 in motion_processor::~motion_processor (this=0x7f993000bbb0, __in_chrg=<optimized out>) at motion_processor.cpp:59
 #2  0x000055db84ebc2d6 in motion_processor::~motion_processor (this=0x7f993000bbb0, __in_chrg=<optimized out>) at motion_processor.cpp:42
 #3  motion_processor::run (this=0x7f993000bbb0) at motion_processor.cpp:201
 #4  0x000055db84ebc8dd in bc_mproc_thread (data=<optimized out>) at motion_processor.cpp:861
 #5  0x00007f99499cea94 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
 #6  0x00007f9949a5ba34 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

According to the documentation, cv::Mat automatically derefs and frees data as needed on being destroyed (e.g. delete)

https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html#ae48d4913285518e2c21a3457017e716e

The bug was introduced by a memory leak fix.

Fixes: 089e6de ("motion_processor: release cv::Mat objects")

This happens when schedule changes from 'M' to 'C'.

This is how it looks in the logs:

 I(1/software): motion_blend_radio is set to 15:1
 I(1/software): motion_debug is set to 0
 I(1/software): Motion detected
 E(): Got connection, but failed to accept
 I(1/software): Switching to new recording schedule 'continuous'
 BUG: Segment violation at 0x0000000000000366
 Call trace:
 [0x000055db84eb8d5b]  @ /usr/sbin/bc-server
 [0x00007f9949977320]  @ /lib/x86_64-linux-gnu/libc.so.6
 [0x00007f994a5c77e9] _ZN2cv3Mat7releaseEv+0x00000000 @ /lib/x86_64-linux-gnu/libopencv_core.so.406
 [0x000055db84eb8ee4]  @ /usr/sbin/bc-server
 [0x000055db84ebc2d6]  @ /usr/sbin/bc-server
 [0x000055db84ebc8dd]  @ /usr/sbin/bc-server
 [0x00007f99499cea94]  @ /lib/x86_64-linux-gnu/libc.so.6
 [0x00007f9949a5ba34] __clone+0x00000000 @ /lib/x86_64-linux-gnu/libc.so.6

This is how it looks in the debugger:

 #0  0x00007f994a5c77e9 in cv::Mat::release() () from /lib/x86_64-linux-gnu/libopencv_core.so.406
 bluecherrydvr#1  0x000055db84eb8ee4 in motion_processor::~motion_processor (this=0x7f993000bbb0, __in_chrg=<optimized out>) at motion_processor.cpp:59
 bluecherrydvr#2  0x000055db84ebc2d6 in motion_processor::~motion_processor (this=0x7f993000bbb0, __in_chrg=<optimized out>) at motion_processor.cpp:42
 bluecherrydvr#3  motion_processor::run (this=0x7f993000bbb0) at motion_processor.cpp:201
 bluecherrydvr#4  0x000055db84ebc8dd in bc_mproc_thread (data=<optimized out>) at motion_processor.cpp:861
 bluecherrydvr#5  0x00007f99499cea94 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
 bluecherrydvr#6  0x00007f9949a5ba34 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

According to the documentation, cv::Mat automatically derefs and frees
data as needed on being destroyed (e.g. delete)

https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html#ae48d4913285518e2c21a3457017e716e

The bug was introduced by a memory leak fix.

Fixes: 089e6de ("motion_processor: release cv::Mat objects")
@andrey-utkin andrey-utkin force-pushed the fix-motion-processor-dtor-crash branch from f0b3840 to 77e9494 Compare December 11, 2024 18:08
@andrey-utkin
Copy link
Contributor Author

Pushed as dde12ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants