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));
|
unigi_ext_type_sound_sample * sample = malloc(sizeof(unigi_ext_type_sound_sample));
|
||||||
if (sample == NULL) { goto fail; }
|
if (sample == NULL) { goto fail; }
|
||||||
int fd = open(path,O_RDONLY);
|
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);
|
size_t size = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
uint8_t * data = malloc(size);
|
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; }
|
if (read(fd,data,size) != size) { goto fail_data; }
|
||||||
close(fd);
|
close(fd);
|
||||||
sample->size = size;
|
sample->size = size;
|
||||||
@ -111,9 +111,10 @@ unigi_ext_type_sound_sample * unigi_ext_sound_open(char * path) {
|
|||||||
|
|
||||||
fail_data:;
|
fail_data:;
|
||||||
free(data);
|
free(data);
|
||||||
|
fail_file:;
|
||||||
|
close(fd);
|
||||||
fail_sample:;
|
fail_sample:;
|
||||||
free(sample);
|
free(sample);
|
||||||
close(fd);
|
|
||||||
fail:;
|
fail:;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user