Added photos to gallery and fixed memory leaks
This commit is contained in:
parent
a50a85046f
commit
27e0036e9d
@ -22,7 +22,9 @@ typedef struct album_s
|
|||||||
|
|
||||||
gallery_t *get_album_list();
|
gallery_t *get_album_list();
|
||||||
gallery_t *new_album_item(char *title);
|
gallery_t *new_album_item(char *title);
|
||||||
|
void free_albums_list(gallery_t *albums_list);
|
||||||
img_t new_img_item(char *path);
|
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);
|
int get_album_imgs(img_t **images_arr, int *size, char *title);
|
||||||
char *gen_gallery_html();
|
char *gen_gallery_html();
|
||||||
|
|
||||||
|
@ -43,6 +43,27 @@ gallery_t *get_album_list()
|
|||||||
return 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
|
* @brief Generates new album item
|
||||||
*
|
*
|
||||||
@ -86,6 +107,18 @@ img_t new_img_item(char *path)
|
|||||||
return img;
|
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)
|
int get_album_imgs(img_t **images_arr, int *size, char *title)
|
||||||
{
|
{
|
||||||
char **photos_list = calloc(0, sizeof(char *));
|
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);
|
fread(image_template, image_file_size, 1, image_template_fp);
|
||||||
fclose(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("");
|
char *gallery_content = strdup("");
|
||||||
|
|
||||||
@ -190,7 +224,7 @@ char *gen_gallery_html()
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(album_template);
|
free(album_template);
|
||||||
free(image_template);
|
free_albums_list(albums_list);
|
||||||
|
|
||||||
return gallery_content;
|
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 |
Loading…
x
Reference in New Issue
Block a user