Skip to content

Fix memory leaks in GIF animation loader #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/image-gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ static twin_animation_t *_twin_animation_from_gif_file(const char *path)
uint8_t *color, *frame;
frame = malloc(gif->width * gif->height * 3);
if (!frame) {
free(anim->frame_delays);
free(anim->frames);
free(anim);
gif_close(gif);
return NULL;
Expand All @@ -584,6 +586,12 @@ static twin_animation_t *_twin_animation_from_gif_file(const char *path)
anim->frames[i] =
twin_pixmap_create(TWIN_ARGB32, gif->width, gif->height);
if (!anim->frames[i]) {
/* Free previously allocated pixmaps */
for (twin_count_t j = 0; j < i; j++)
twin_pixmap_destroy(anim->frames[j]);
free(frame);
free(anim->frame_delays);
free(anim->frames);
free(anim);
gif_close(gif);
return NULL;
Expand Down Expand Up @@ -617,7 +625,12 @@ static twin_animation_t *_twin_animation_from_gif_file(const char *path)
}
anim->iter = twin_animation_iter_init(anim);
if (!anim->iter) {
/* Free all allocated pixmaps */
for (twin_count_t i = 0; i < frame_count; i++)
twin_pixmap_destroy(anim->frames[i]);
free(frame);
free(anim->frame_delays);
free(anim->frames);
free(anim);
gif_close(gif);
return NULL;
Expand Down