6887292: memory leak in freetypeScaler.c
authorigor
Fri, 02 Oct 2009 10:15:12 -0700
changeset 4243 657b5136de1a
parent 3939 be73148d80c8
child 4244 c92d0ad47a06
6887292: memory leak in freetypeScaler.c Reviewed-by: bae, prr
jdk/src/share/native/sun/font/freetypeScaler.c
--- a/jdk/src/share/native/sun/font/freetypeScaler.c	Tue Sep 29 22:49:43 2009 -0700
+++ b/jdk/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);
 }