diff --git a/src/image-gif.c b/src/image-gif.c index 867fa10..4b7ceb2 100644 --- a/src/image-gif.c +++ b/src/image-gif.c @@ -554,7 +554,18 @@ static twin_animation_t *_twin_animation_from_gif_file(const char *path) anim->n_frames = frame_count; anim->frames = malloc(sizeof(twin_pixmap_t *) * frame_count); + if (!anim->frames) { + free(anim); + gif_close(gif); + return NULL; + } anim->frame_delays = malloc(sizeof(twin_time_t) * frame_count); + if (!anim->frame_delays) { + free(anim->frames); + free(anim); + gif_close(gif); + return NULL; + } gif_rewind(gif); uint8_t *color, *frame; diff --git a/src/path.c b/src/path.c index c8e4cde..701cf9a 100644 --- a/src/path.c +++ b/src/path.c @@ -581,6 +581,8 @@ twin_path_t *twin_path_create(void) twin_path_t *path; path = malloc(sizeof(twin_path_t)); + if (!path) + return NULL; path->npoints = path->size_points = 0; path->nsublen = path->size_sublen = 0; path->points = 0; diff --git a/src/poly.c b/src/poly.c index 93d7478..d4eb907 100644 --- a/src/poly.c +++ b/src/poly.c @@ -302,6 +302,8 @@ void twin_fill_path(twin_pixmap_t *pixmap, int nalloc = path->npoints + path->nsublen + 1; twin_edge_t *edges = malloc(sizeof(twin_edge_t) * nalloc); + if (!edges) + return; int p = 0; int nedges = 0; for (int s = 0; s <= path->nsublen; s++) { diff --git a/src/window.c b/src/window.c index a9f2fe4..1d111b8 100644 --- a/src/window.c +++ b/src/window.c @@ -208,6 +208,8 @@ void twin_window_set_name(twin_window_t *window, const char *name) window->name = malloc(strlen(name) + 1); if (window->name) strcpy(window->name, name); + else + window->name = NULL; /* Ensure consistent state on allocation failure */ twin_window_draw(window); }