vector释放奔溃

问题:程序奔溃,报错:线程 0x9e90 已退出,返回值为 -1073740777 (0xc0000417)。

过程:调试程序,在退出某个函数时,程序异常退出,F11跟进,发现是vector变量释放时导致的奔溃。

原因:https://blog.csdn.net/lanbing510/article/details/40585789

The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The local heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamic-link library (DLL) contains a static link to the run-time library, it has its own instance of the run-time heap, and therefore its own heap, independent of the application's local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer are removed during preprocessing.

由于dll独立于程序,外部无法释放该dll中的堆栈空间。

本次无法释放的vector变量的空间由OpenCV函数imencode(".jpg", src, buf, param)申请,无法在外部释放。

文章也指出另一可能是VS的版本和OpenCV的版本不同造成。

解决:在使用imencode前,未vector变量分配空间std::vector<BYTE> buf = std::vector<BYTE>(DataSize);

猜你喜欢

转载自www.cnblogs.com/zzx-blog/p/11455483.html