Skip to content

Commit 9e605dc

Browse files
authored
Merge pull request #115 from sysprog21/fix-null-pointer
Fix NULL pointer dereferences after malloc
2 parents c8834d1 + 1fd272a commit 9e605dc

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/image-gif.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,18 @@ static twin_animation_t *_twin_animation_from_gif_file(const char *path)
554554

555555
anim->n_frames = frame_count;
556556
anim->frames = malloc(sizeof(twin_pixmap_t *) * frame_count);
557+
if (!anim->frames) {
558+
free(anim);
559+
gif_close(gif);
560+
return NULL;
561+
}
557562
anim->frame_delays = malloc(sizeof(twin_time_t) * frame_count);
563+
if (!anim->frame_delays) {
564+
free(anim->frames);
565+
free(anim);
566+
gif_close(gif);
567+
return NULL;
568+
}
558569

559570
gif_rewind(gif);
560571
uint8_t *color, *frame;

src/path.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ twin_path_t *twin_path_create(void)
581581
twin_path_t *path;
582582

583583
path = malloc(sizeof(twin_path_t));
584+
if (!path)
585+
return NULL;
584586
path->npoints = path->size_points = 0;
585587
path->nsublen = path->size_sublen = 0;
586588
path->points = 0;

src/poly.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ void twin_fill_path(twin_pixmap_t *pixmap,
302302

303303
int nalloc = path->npoints + path->nsublen + 1;
304304
twin_edge_t *edges = malloc(sizeof(twin_edge_t) * nalloc);
305+
if (!edges)
306+
return;
305307
int p = 0;
306308
int nedges = 0;
307309
for (int s = 0; s <= path->nsublen; s++) {

src/window.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ void twin_window_set_name(twin_window_t *window, const char *name)
208208
window->name = malloc(strlen(name) + 1);
209209
if (window->name)
210210
strcpy(window->name, name);
211+
else
212+
window->name = NULL; /* Ensure consistent state on allocation failure */
211213
twin_window_draw(window);
212214
}
213215

0 commit comments

Comments
 (0)