Added photos to gallery and fixed memory leaks

This commit is contained in:
Dmitriy Shishkov 2021-04-10 13:37:31 +05:00
parent a50a85046f
commit 27e0036e9d
No known key found for this signature in database
GPG Key ID: 7CAE12ED13853CAC
8 changed files with 38 additions and 2 deletions

View File

@ -22,7 +22,9 @@ typedef struct album_s
gallery_t *get_album_list();
gallery_t *new_album_item(char *title);
void free_albums_list(gallery_t *albums_list);
img_t new_img_item(char *path);
void free_img_item(img_t img);
int get_album_imgs(img_t **images_arr, int *size, char *title);
char *gen_gallery_html();

View File

@ -43,6 +43,27 @@ gallery_t *get_album_list()
return list;
}
/**
* @brief Free gallery_t structure
*
* @return void
*/
void free_albums_list(gallery_t *albums_list)
{
gallery_t *curr_item = albums_list;
while (curr_item != 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);
}
/**
* @brief Generates new album item
*
@ -86,6 +107,18 @@ img_t new_img_item(char *path)
return img;
}
/**
* @brief Free img_t structure
*
* @return void
*/
void free_img_item(img_t img)
{
free(img.description);
free(img.path);
free(img.tags);
}
int get_album_imgs(img_t **images_arr, int *size, char *title)
{
char **photos_list = calloc(0, sizeof(char *));
@ -135,7 +168,8 @@ char *gen_gallery_html()
fread(image_template, image_file_size, 1, image_template_fp);
fclose(image_template_fp);
gallery_t *albums_list_item = get_album_list();
gallery_t *albums_list = get_album_list();
gallery_t *albums_list_item = albums_list;
char *gallery_content = strdup("");
@ -190,7 +224,7 @@ char *gen_gallery_html()
}
free(album_template);
free(image_template);
free_albums_list(albums_list);
return gallery_content;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB