symisc / sod

An Embedded Computer Vision & Machine Learning Library (CPU Optimized & IoT Capable)
https://sod.pixlab.io
Other
1.75k stars 213 forks source link

Memory allocating #10

Closed serge2051 closed 5 years ago

serge2051 commented 5 years ago

I was trying to use SOD for plate detection. At the code, you are using malloc for allocating memory, but not carry about "value" that is "filled" at the allocated space. For example, in sod.c:10828(sod_canny_edge_image) you allocate memory for variable "dir" and then using it in some functions. At sod.c:10521 you are using this variable "dir" with comparing of elements, contained at "dir" with 0, 1, 2 and 3-int values at the switch/case construction. It's not correct, because at the allocated memory can be garbage with different values. When I was using VisualStudio program was working OK, but not for MinGW: MinGW set allocated memory to "0"-values and I catch a SEGFAULT signal. So if I paste after allocating memory memset(dir, INT_MIN, im.w * im.h * sizeof(int)); All is working OK at the different compilers. So my suggestion is to use memset always after allocating memory. Additional info: OS Windows 10, Compiler - g++ (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 7.2.0.

symisc commented 5 years ago

Thanks for reporting this issue. We mainly use MSVC as the default compiler on Windows systems that's why we didn't notice this issue. memsetting memory is more than advised. We'll push this behavior on the next release of the library.