Commit b6cb4997e8f0accd98b9589f29e4654e8002501f

Werner Lemberg 2015-02-06T08:46:06

[autofit] Fix potential memory leak. While this doesn't show up with FreeType, exactly the same code leaks with ttfautohint's modified auto-hinter code (which gets used in a slightly different way). It certainly doesn't harm since it is similar to already existing checks in the code for embedded arrays. * src/autofit/afhints.c (af_glyph_hints_reload): Set `max_contours' and `max_points' for all cases.

diff --git a/ChangeLog b/ChangeLog
index 15cc4c7..bf60542 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2015-02-06  Werner Lemberg  <wl@gnu.org>
+
+	[autofit] Fix potential memory leak.
+
+	While this doesn't show up with FreeType, exactly the same code
+	leaks with ttfautohint's modified auto-hinter code (which gets used
+	in a slightly different way).
+
+	It certainly doesn't harm since it is similar to already existing
+	checks in the code for embedded arrays.
+
+	* src/autofit/afhints.c (af_glyph_hints_reload): Set `max_contours'
+	and `max_points' for all cases.
+
 2015-01-31  Werner Lemberg  <wl@gnu.org>
 
 	[autofit] Add support for Thai script.
diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c
index 56bc386..8b0e1b0 100644
--- a/src/autofit/afhints.c
+++ b/src/autofit/afhints.c
@@ -615,7 +615,13 @@
     old_max = hints->max_contours;
 
     if ( new_max <= AF_CONTOURS_EMBEDDED )
-      hints->contours = hints->embedded.contours;
+    {
+      if ( hints->contours == NULL )
+      {
+        hints->contours     = hints->embedded.contours;
+        hints->max_contours = AF_CONTOURS_EMBEDDED;
+      }
+    }
     else if ( new_max > old_max )
     {
       if ( hints->contours == hints->embedded.contours )
@@ -638,7 +644,13 @@
     old_max = hints->max_points;
 
     if ( new_max <= AF_POINTS_EMBEDDED )
-      hints->points = hints->embedded.points;
+    {
+      if ( hints->points == NULL )
+      {
+        hints->points     = hints->embedded.points;
+        hints->max_points = AF_POINTS_EMBEDDED;
+      }
+    }
     else if ( new_max > old_max )
     {
       if ( hints->points == hints->embedded.points )