From 96fc21a3cd7ea1e3e4bc77310155b6116db67bbb Mon Sep 17 00:00:00 2001 From: Fierelier Date: Tue, 22 Oct 2024 09:26:03 +0200 Subject: [PATCH] Fix memory leak --- main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 31421c3..67558f9 100644 --- a/main.c +++ b/main.c @@ -98,11 +98,11 @@ unigi_ext_type_sound_sample * unigi_ext_sound_open(char * path) { unigi_ext_type_sound_sample * sample = malloc(sizeof(unigi_ext_type_sound_sample)); if (sample == NULL) { goto fail; } int fd = open(path,O_RDONLY); - if (fd == -1) { goto fail; } + if (fd == -1) { goto fail_sample; } size_t size = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); uint8_t * data = malloc(size); - if (data == NULL) { goto fail_sample; } + if (data == NULL) { goto fail_file; } if (read(fd,data,size) != size) { goto fail_data; } close(fd); sample->size = size; @@ -111,9 +111,10 @@ unigi_ext_type_sound_sample * unigi_ext_sound_open(char * path) { fail_data:; free(data); + fail_file:; + close(fd); fail_sample:; free(sample); - close(fd); fail:; return NULL; }