nsxiv19b4719
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.
+2 −4
1 file changed
- M main.c +2 −4
| @@ -195,13 +195,11 @@ void remove_file(int n, bool manual) | |||
| 195 | 195 | if (files[n].path != files[n].name) | |
| 196 | 196 | free((void*) files[n].path); | |
| 197 | 197 | free((void*) files[n].name); | |
| 198 | + | if (tns.thumbs != NULL) | |
| 199 | + | tns_unload(&tns, n); | |
| 198 | 200 | ||
| 199 | 201 | if (n + 1 < filecnt) { | |
| 200 | 202 | if (tns.thumbs != NULL) { | |
| 201 | − | if (tns.thumbs[n].im != NULL) { | |
| 202 | − | imlib_context_set_image(tns.thumbs[n].im); | |
| 203 | − | imlib_free_image_and_decache(); | |
| 204 | − | } | |
| 205 | 203 | memmove(tns.thumbs + n, tns.thumbs + n + 1, (filecnt - n - 1) * | |
| 206 | 204 | sizeof(*tns.thumbs)); | |
| 207 | 205 | memset(tns.thumbs + filecnt - 1, 0, sizeof(*tns.thumbs)); | |