Fixed unfreed memory and files handling errors
This commit is contained in:
@ -10,9 +10,9 @@
|
||||
*/
|
||||
gallery_t *get_album_list()
|
||||
{
|
||||
gallery_t *list = NULL, *curr = list;
|
||||
gallery_t *list = NULL, *curr;
|
||||
|
||||
char **albums_titles_list = malloc(0);
|
||||
char **albums_titles_list = NULL;
|
||||
|
||||
ssize_t albums_am = get_dir_list(&albums_titles_list, GALLERY_ROOT);
|
||||
|
||||
@ -50,18 +50,18 @@ gallery_t *get_album_list()
|
||||
*/
|
||||
void free_albums_list(gallery_t *albums_list)
|
||||
{
|
||||
gallery_t *curr_item = albums_list;
|
||||
|
||||
while (curr_item != NULL)
|
||||
while (albums_list != NULL)
|
||||
{
|
||||
free(curr_item->title);
|
||||
for (int i = 0; i < curr_item->img_am; i++)
|
||||
free_img_item(curr_item->images[i]);
|
||||
free(curr_item->images);
|
||||
curr_item = curr_item->next;
|
||||
free(albums_list->title);
|
||||
for (int i = 0; i < albums_list->img_am; i++)
|
||||
free_img_item(albums_list->images[i]);
|
||||
free(albums_list->images);
|
||||
|
||||
gallery_t *next_item = albums_list->next;
|
||||
free(albums_list);
|
||||
albums_list = next_item;
|
||||
}
|
||||
|
||||
free(albums_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +154,15 @@ int get_album_imgs(img_t **images_arr, int *size, char *title)
|
||||
char *gen_gallery_html()
|
||||
{
|
||||
FILE *album_template_fp = fopen("static/gallery/album.html", "r");
|
||||
if (album_template_fp == NULL) {
|
||||
return "500 Internal Error\n";
|
||||
}
|
||||
|
||||
FILE *image_template_fp = fopen("static/gallery/image.html", "r");
|
||||
if (image_template_fp == NULL) {
|
||||
fclose(album_template_fp);
|
||||
return "500 Internal Error\n";
|
||||
}
|
||||
|
||||
size_t album_file_size = get_file_size(album_template_fp) + 1;
|
||||
char *album_template = calloc(1, album_file_size);
|
||||
|
Reference in New Issue
Block a user