changeset 1877:31e68419715e

6887292: memory leak in freetypeScaler.c Reviewed-by: bae, prr
author igor
date Fri, 02 Oct 2009 10:15:12 -0700
parents 5b52851b0927
children ccc36189f2a7
files src/share/native/sun/font/freetypeScaler.c
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/font/freetypeScaler.c	Tue Sep 29 22:49:43 2009 -0700
+++ b/src/share/native/sun/font/freetypeScaler.c	Fri Oct 02 10:15:12 2009 -0700
@@ -102,9 +102,21 @@
 }
 
 static void freeNativeResources(JNIEnv *env, FTScalerInfo* scalerInfo) {
+    void *stream;
+
     if (scalerInfo == NULL)
         return;
 
+    //apparently Done_Face will only close the stream
+    // but will not relase the memory of stream structure.
+    // We need to free it explicitly to avoid leak.
+    //Direct access to the stream field might be not ideal solution as
+    // it is considred to be "private".
+    //Alternatively we could have stored pointer to the structure
+    // in the scalerInfo but this will increase size of the structure
+    // for no good reason
+    stream = scalerInfo->face->stream;
+
     FT_Done_Face(scalerInfo->face);
     FT_Done_FreeType(scalerInfo->library);
 
@@ -116,6 +128,10 @@
         free(scalerInfo->fontData);
     }
 
+   if (stream != NULL) {
+        free(stream);
+   }
+
     free(scalerInfo);
 }