Memory allocation and deallocation issues in c++ code

I am porting an image processing app using a camera developed by Android to IOS, and try to use C++ code used by Android in IOS.

Install the necessary library and link the target c++ code using objective-c wrapper.

The problem is that when a function with particularly large number of memory allocation/release ends in the C++ code, an error is definitely issued as the local variables are released.

Error:

Corrupt value: 0x3fc93ba18499360a
GBCare(20641,0x16bcfb000) malloc: *** set a breakpoint in malloc_error_break to debug
GBCare(20641,0x16bcfb000) malloc: Incorrect checksum for freed object 0x11556d1e0: probably modified after being freed.
Corrupt value: 0x3fc93ba18499360a

Additionally, the same error occurs sometimes at the location where the type of memory is allocated (e.g., cv::Mat.clone, cv:Mat::zeros) and we checked that the correct parameter was included.

I don't know what it means, but if you do it as shown in the picture below in Product-Scheme-Edit Scheme, it works normally without errors.

I think it's not a code problem, but a problem that occurs in the environment setting, so please help me.

Development environment: Xcode 13.2.1 / Swift5 / OpenCV 4.3

set lines 877 to null and see if the any of the messages go away. If you're releasing objects you shouldn't be making new assignments after freeing ...

I think it's not a code problem

You are almost certainly wrong about that. When working in a low-level language, like C or C++, errors like this are almost always the result of the code in question breaking those languages extremely hard-to-follow memory management rules. You often notice these problems when porting code between platforms because different platforms behave differently when you break the rules.

A good place to start here is the Address Sanitizer.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Memory allocation and deallocation issues in c++ code
 
 
Q