Skip to content

Commit 06a8717

Browse files
committed
Fix the heap-use-after-free and memory leak
To fix the heap-use-after-free issue when 'screen' is accessed by the 'twin_sdl_work()' function, remove the '_twin_sdl_destroy(screen, tx)' operation. Additionally, to address the memory leak, add the 'twin_path_destroy(path)' function to ensure the unused path is properly destroyed. Add the operation to deallocate 'frame', as it will no longer be used in the future. Close #49
1 parent 9530bc5 commit 06a8717

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

apps/multi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ static void apps_jelly_start(twin_screen_t *screen, int x, int y, int w, int h)
216216
twin_path_destroy(stroke);
217217
}
218218
}
219+
twin_path_destroy(path);
219220
twin_window_show(window);
220221
}
221222

backend/sdl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ static void _twin_sdl_destroy(twin_screen_t *screen, twin_sdl_t *tx)
6262
SDL_DestroyRenderer(tx->render);
6363
SDL_DestroyWindow(tx->win);
6464
SDL_Quit();
65-
66-
twin_screen_destroy(screen);
6765
}
6866

6967
static void twin_sdl_damage(twin_screen_t *screen, twin_sdl_t *tx)

src/image-gif.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,12 @@ static twin_animation_t *_twin_animation_from_gif_file(const char *path)
600600
}
601601
anim->iter = twin_animation_iter_init(anim);
602602
if (!anim->iter) {
603+
free(frame);
603604
free(anim);
604605
gif_close(gif);
605606
return NULL;
606607
}
608+
free(frame);
607609
gif_close(gif);
608610
return anim;
609611
}

0 commit comments

Comments
 (0)