symisc/sod

Invalid read of size 4

Closed this issue · 9 comments

Memory checking a program with valgrind returns an invalid read of size 4 in at line 10533 of sod.c.

Minimal example code :

#include <stdlib.h>
#include <math.h>
#include "sod.h"

int main(int argc, char *argv[]) {
	const char *zInput = argv[1];
	sod_img imgIn = sod_img_load_grayscale(zInput);
	sod_img cannyImg = sod_canny_edge_image(imgIn, 0);
	sod_free_image(cannyImg);
	return 0;
}

Valgrind output after compilation in Ubuntu 18.04 amd 64 :

==17492== Invalid read of size 4
==17492==    at 0x1286F8: canny_non_max_suppression (sod.c:10533)
==17492==    by 0x129D0E: sod_canny_edge_image (sod.c:10832)
==17492==    by 0x10B534: main (minimal.c:8)
==17492==  Address 0x4d57f00 is 0 bytes after a block of size 473,600 alloc'd
==17492==    at 0x483AB35: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==17492==    by 0x1234A3: sod_make_image (sod.c:9190)
==17492==    by 0x129C67: sod_canny_edge_image (sod.c:10827)
==17492==    by 0x10B534: main (minimal.c:8)
==17492== 

Yes, this is an issue with memory allocation of an array that may run out of bound in some cases. A fix is to be pushed in the coming weeks with the next release of the library.

Ok, good to know you are aware of that 👍.

I also faced a memory leak in canny detector which sometimes leaks 128 bytes and sometimes not ? I am still trying to discover how exactly but it is happening around line 966 in SysSetPut

For the memory leak, I am sorry the problem was on my side. I was not always releasing the lines while doing hough lines detection.

Everything fine there. Nice work by the way !

Any idea when the next library release will be coming out ?

Any news on the new library release ?

Cheers

The release is scheduled for January 2020 due time constraint and developers focusing on a global scale product powered by SOD. We have managed to fix the canny edge issue and adding new image processing interfaces. Stay tune!

Make sure to update to the latest version of SOD which fix the canny edge detection memory leak issue https://sod.pixlab.io/changelog.html