< prev index next >

src/java.desktop/share/native/libfontmanager/freetypeScaler.c

Print this page

        

*** 58,67 **** --- 58,68 ---- NB: We may consider switching to JNI_GetEnv. */ JNIEnv* env; FT_Library library; FT_Face face; + FT_Stream faceStream; jobject font2D; jobject directBuffer; unsigned char* fontData; unsigned fontDataOffset;
*** 105,124 **** 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); if (scalerInfo->directBuffer != NULL) { (*env)->DeleteGlobalRef(env, scalerInfo->directBuffer); --- 106,119 ---- void *stream; if (scalerInfo == NULL) return; ! // FT_Done_Face always closes the stream, but only frees the memory ! // of the data structure if it was internally allocated by FT. ! // We hold on to a pointer to the stream structure if we provide it ! // ourselves, so that we can free it here. FT_Done_Face(scalerInfo->face); FT_Done_FreeType(scalerInfo->library); if (scalerInfo->directBuffer != NULL) { (*env)->DeleteGlobalRef(env, scalerInfo->directBuffer);
*** 126,139 **** if (scalerInfo->fontData != NULL) { free(scalerInfo->fontData); } ! if (stream != NULL) { ! free(stream); } - free(scalerInfo); } /* invalidates state of java scaler object */ static void invalidateJavaScaler(JNIEnv *env, --- 121,133 ---- if (scalerInfo->fontData != NULL) { free(scalerInfo->fontData); } ! if (scalerInfo->faceStream != NULL) { ! free(scalerInfo->faceStream); } free(scalerInfo); } /* invalidates state of java scaler object */ static void invalidateJavaScaler(JNIEnv *env,
*** 300,309 **** --- 294,306 ---- error = FT_Open_Face(scalerInfo->library, &ft_open_args, indexInCollection, &scalerInfo->face); + if (!error) { + scalerInfo->faceStream = ftstream; + } } if (error || scalerInfo->directBuffer == NULL) { free(ftstream); } }
< prev index next >