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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions server/motion_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ motion_processor::motion_processor(bc_record *bcRecord)

memset(&m_debugEventTime, 0, sizeof(struct tm));
m_debugEventTime.tm_sec = -1;

// m_refFrames[2] is a static array so ctors, dtors are not called automatically on elements
new(&m_refFrames[0]) cv::Mat();
new(&m_refFrames[1]) cv::Mat();
}

motion_processor::~motion_processor()
Expand All @@ -55,9 +59,9 @@ motion_processor::~motion_processor()
}
#endif

for (int i = 0; i < sizeof(m_refFrames); i++) {
m_refFrames[i].release();
}
// m_refFrames[2] is a static array so ctors, dtors are not called automatically on elements
m_refFrames[0].~Mat();
m_refFrames[1].~Mat();
delete output_source;
}

Expand Down Expand Up @@ -579,7 +583,6 @@ int motion_processor::detect_opencv(AVFrame *rawFrame)
// first things first... get the original frame from the AVFrame and convert it to an OpenCV Grayscale Mat, and the "downscale" size.
cv::Mat m = cv::Mat(dst_h, dst_w, CV_8UC1);
if (convert_AVFrame_to_grayMat(rawFrame, m) == 0) {
m.release();
return 0; // error converting frame...
}

Expand Down Expand Up @@ -620,7 +623,6 @@ int motion_processor::detect_opencv(AVFrame *rawFrame)

if (m_motionDebug)
check_for_new_debug_event(ret);
m.release();
return ret;
}

Expand All @@ -633,7 +635,6 @@ int motion_processor::detect_opencv_advanced(AVFrame *rawFrame)
// first things first... get the original frame from the AVFrame and convert it to an OpenCV Grayscale Mat, and the "downscale" size.
cv::Mat m = cv::Mat(dst_h, dst_w, CV_8UC1);
if (convert_AVFrame_to_grayMat(rawFrame, m) == 0) {
m.release();
return 0; // error converting frame...
}

Expand Down Expand Up @@ -669,7 +670,6 @@ int motion_processor::detect_opencv_advanced(AVFrame *rawFrame)
}

m_motionTriggered = (num_md_frames >= m_minMotionFrames);
m.release();
return m_motionTriggered;
}

Expand Down
Loading