From 5dbd230b3ae0f0a121f7aa35ee9a9dc1d6ff6ac2 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 9 Jul 2024 22:00:39 +0800 Subject: [PATCH] Fix bug#71929 * src/image.c (free_image_cache): Unconditionally release image cache, as this function is only called with its existence already established. * src/xfaces.c (free_frame_faces): Clear FRAME_IMAGE_CACHE (f). (bug#71929) (cherry picked from commit 8350ebd22e983df5eb9ad33d427bd3d6a09ffe7f) --- src/dispextern.h | 2 +- src/image.c | 21 ++++++++------------- src/xfaces.c | 5 +++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/dispextern.h b/src/dispextern.h index 51dc354d37c..cc248a4472e 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3653,7 +3653,7 @@ extern void x_kill_gs_process (Pixmap, struct frame *); extern Lisp_Object image_find_image_file (Lisp_Object); struct image_cache *make_image_cache (void); -void free_image_cache (struct frame *); +extern void free_image_cache (struct frame *); void clear_image_caches (Lisp_Object); void mark_image_cache (struct image_cache *); void image_prune_animation_caches (bool); diff --git a/src/image.c b/src/image.c index 2945447b962..2ee2f3245be 100644 --- a/src/image.c +++ b/src/image.c @@ -2304,23 +2304,18 @@ void free_image_cache (struct frame *f) { struct image_cache *c = FRAME_IMAGE_CACHE (f); - if (c) - { - ptrdiff_t i; + ptrdiff_t i; - /* Cache should not be referenced by any frame when freed. */ - eassert (c->refcount == 0); + /* Cache should not be referenced by any frame when freed. */ + eassert (c->refcount == 0); - for (i = 0; i < c->used; ++i) - free_image (f, c->images[i]); - xfree (c->images); - xfree (c->buckets); - xfree (c); - FRAME_IMAGE_CACHE (f) = NULL; - } + for (i = 0; i < c->used; ++i) + free_image (f, c->images[i]); + xfree (c->images); + xfree (c->buckets); + xfree (c); } - /* Clear image cache of frame F. FILTER=t means free all images. FILTER=nil means clear only images that haven't been displayed for some time. diff --git a/src/xfaces.c b/src/xfaces.c index 188dd4778bc..684b6ccfac7 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -712,6 +712,11 @@ free_frame_faces (struct frame *f) --image_cache->refcount; if (image_cache->refcount == 0) free_image_cache (f); + + /* The `image_cache' field must be emptied, in case references + to this dead frame should remain and be scanned by GC. + (bug#71929) */ + FRAME_IMAGE_CACHE (f) = NULL; } } #endif /* HAVE_WINDOW_SYSTEM */ -- 2.39.5