mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 13:16:32 -06:00
When OpenCV is built with -DENABLE_INSTRUMENTATION=ON, calling cv::parallel_for_ (for example via cv::cvtColor) from any thread other than the one that initialized cv::instr::InstrStruct crashed with a null-pointer dereference in ParallelLoopBodyWrapperContext::finalize(). Because InstrTLSStruct::pCurrentNode defaults to NULL on newly created threads and InstrStruct only initializes the constructing thread's TLS slot, finalize() dereferenced a null pThreadRoot. The same null-pointer assumption existed in the error and exception branches of CV_INSTRUMENT_FUN_RT_META and CV_INSTRUMENT_FUN_RV_META, where cv::instr::getCurrentNode() was dereferenced unconditionally. This change guards both pThreadRoot in ParallelLoopBodyWrapperContext::finalize() and cv::instr::getCurrentNode() in the instrumentation function-wrapper macros, matching the existing null check in IntrumentationRegion and OPENCV_TRACE's if (traceRootRegion) check.