Fix memory leak
This commit is contained in:
parent
72fea79aec
commit
96fc21a3cd
7
main.c
7
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user