aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2023-03-04 08:01:19 +0100
committerNRK <nrk@disroot.org>2023-03-04 08:01:19 +0100
commit19b47192f21939b46a8f46d131c31f138aaa3b33 (patch)
tree4296ab614ba3d549f609b75329d2936a8dcbc93c /main.c
parent8f0322c2e33cd39208bd2693fde968ba47a93e6e (diff)
downloadnsxiv-19b47192f21939b46a8f46d131c31f138aaa3b33.tar.zst
fix: thumbnail leak when removing the last file (#423)
bf6c062 tried to fixed the thumbnail leak, but it was done inside a `if (n+1 < filecnt)` branch, meaning the thumbnail was still leaking away whenever the last file was removed. we need to unload the thumb regardless of whether it's in the middle or not. this bug was caught due to the recent `assert`s that were added in 01f3cf2. Closes: https://codeberg.org/nsxiv/nsxiv/issues/422 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/423 Reviewed-by: eylles <eylles@noreply.codeberg.org> Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
Diffstat (limited to 'main.c')
-rw-r--r--main.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/main.c b/main.c
index eed945c..9541b6d 100644
--- a/main.c
+++ b/main.c
@@ -195,13 +195,11 @@ void remove_file(int n, bool manual)
if (files[n].path != files[n].name)
free((void*) files[n].path);
free((void*) files[n].name);
+ if (tns.thumbs != NULL)
+ tns_unload(&tns, n);
if (n + 1 < filecnt) {
if (tns.thumbs != NULL) {
- if (tns.thumbs[n].im != NULL) {
- imlib_context_set_image(tns.thumbs[n].im);
- imlib_free_image_and_decache();
- }
memmove(tns.thumbs + n, tns.thumbs + n + 1, (filecnt - n - 1) *
sizeof(*tns.thumbs));
memset(tns.thumbs + filecnt - 1, 0, sizeof(*tns.thumbs));