diff --git a/Makefile b/Makefile index d2fbe13..30713bb 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,8 @@ NVCCFLAGS += # -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable # Compile with debug # -g +# See memory leaks and Incorrect Read/Write +# -fsanitize=address -lasan all: mnist cnn; # diff --git a/src/cnn/jpeg.c b/src/cnn/jpeg.c index fb522a2..dd03f62 100644 --- a/src/cnn/jpeg.c +++ b/src/cnn/jpeg.c @@ -203,9 +203,7 @@ void free_dataset(jpegDataset* dataset) { } free(dataset->fileNames); free(dataset->labels); - #ifdef STORE_IMAGES_TO_RAM free(dataset->images); - #endif free(dataset); } diff --git a/src/mnist/utils.c b/src/mnist/utils.c index a5cf8e9..f9ea07d 100644 --- a/src/mnist/utils.c +++ b/src/mnist/utils.c @@ -63,9 +63,7 @@ void print_weights(char* filename) { void count_labels(char* filename) { uint32_t number_of_images = read_mnist_labels_nb_images(filename); - - unsigned int* labels = (unsigned int*)malloc(sizeof(unsigned int)*number_of_images); - labels = read_mnist_labels(filename); + unsigned int* labels = read_mnist_labels(filename); unsigned int tab[10]; diff --git a/test/mnist_data_io.c b/test/mnist_data_io.c index b74ccb1..ae2aef5 100644 --- a/test/mnist_data_io.c +++ b/test/mnist_data_io.c @@ -49,5 +49,14 @@ int main() { read_test(nb_images, width, height, images, labels); printf(GREEN "OK\n" RESET); + for (int i=0; i < nb_images; i++) { + for (int j=0; j < height; j++) { + free(images[i][j]); + } + free(images[i]); + } + free(images); + free(labels); + free(parameters); return 0; } \ No newline at end of file