Fix various memory leaks

This commit is contained in:
augustin64 2023-01-14 14:30:34 +01:00
parent 2ac811ca78
commit b6aafbf0fd
4 changed files with 12 additions and 5 deletions

View File

@ -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;
#

View File

@ -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);
}

View File

@ -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];

View File

@ -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;
}