beh

X11 image viewer
git clone https://git.porkepik.fr/beh
Log | Files | Refs | README | LICENSE

commit bcf569b32c90042b40c2fcf0708ca2bef755be75
parent 37b5300adbd1a925a67c2c3b4e05284ea4a94f97
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Fri, 26 Jun 2020 21:41:16 +0200

fix memory leak

Diffstat:
Mbeh.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/beh.c b/beh.c @@ -150,6 +150,14 @@ init_img(char *filepath) return 0; } +static void +free_img(void) +{ + if (img.dpy_data != img.data) + free(img.dpy_data); + stbi_image_free(img.data); +} + static unsigned char * resize(int new_w, int new_h) { @@ -291,6 +299,7 @@ event_loop() } else if (keysym == XK_p) { if (imgid == 0) break; + free_img(); do { imgid--; status = init_img(filepaths[imgid]); @@ -301,6 +310,7 @@ event_loop() } else if (keysym == XK_n) { if (imgid == nimgs - 1) break; + free_img(); do { imgid++; status = init_img(filepaths[imgid]); @@ -392,9 +402,7 @@ main(int argc, char **argv) XDestroyWindow(dpy, app.win); XCloseDisplay(dpy); - if (img.dpy_data != img.data) - free(img.dpy_data); - stbi_image_free(img.data); + free_img(); free(filepaths); return 0;