]> git.eshelyaron.com Git - emacs.git/commitdiff
Prevent double frees in closing fonts provided by the Haiku font driver
authorPo Lu <luangruo@yahoo.com>
Sun, 18 May 2025 00:46:27 +0000 (08:46 +0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 21 May 2025 06:09:21 +0000 (08:09 +0200)
* src/haikufont.c (haikufont_close): Clear INFO->metrics,
glyphs, be_font after they are released and do not attempt to
access them if NULL.  (bug#77478)

(cherry picked from commit b9b52f009289ede7967a176bc6ed069c87514794)

src/haikufont.c

index 7522b92207fa0c4e98b83000f179940e6740e401..29a76e674a51217f9063be8730b68e2e6e32fa44 100644 (file)
@@ -890,25 +890,32 @@ haikufont_close (struct font *font)
     return;
 
   block_input ();
-  if (info && info->be_font)
+  if (info->be_font)
     BFont_close (info->be_font);
 
-  for (i = 0; i < info->metrics_nrows; i++)
+  if (info->metrics)
     {
-      if (info->metrics[i])
-       xfree (info->metrics[i]);
+      for (i = 0; i < info->metrics_nrows; i++)
+       {
+         if (info->metrics[i])
+           xfree (info->metrics[i]);
+       }
+      xfree (info->metrics);
     }
 
-  if (info->metrics)
-    xfree (info->metrics);
-
-  for (i = 0; i < 0x100; ++i)
+  if (info->glyphs)
     {
-      if (info->glyphs[i])
-       xfree (info->glyphs[i]);
+      for (i = 0; i < 0x100; ++i)
+       {
+         if (info->glyphs[i])
+           xfree (info->glyphs[i]);
+       }
+      xfree (info->glyphs);
     }
 
-  xfree (info->glyphs);
+  info->metrics = NULL;
+  info->glyphs = NULL;
+  info->be_font = NULL;
   unblock_input ();
 }