[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug awt/36289] New: Memory Leak in gtk-peer CairoGraphics2D.cairoDrawGl
From: |
softa at ttechgroup dot com |
Subject: |
[Bug awt/36289] New: Memory Leak in gtk-peer CairoGraphics2D.cairoDrawGlyphVector native function (classpath 0.97.1) |
Date: |
21 May 2008 11:27:15 -0000 |
Hi All,
I found a memory-leak bug in gnu_java_awt_peer_gtk_CairoGraphics2D.c, function
Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoDrawGlyphVector(...)
This leakage is related to all text rendering methods in awt and swing, that
uses Graphics.drawString(...)
here is the code from gnu_java_awt_peer_gtk_CairoGraphics2D.c (0.97.1)
...
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoDrawGlyphVector
(JNIEnv *env, jobject obj __attribute__((unused)), jlong pointer,
jobject font,
jfloat x, jfloat y, jint n,
jintArray java_codes,
jfloatArray java_positions, jlongArray java_fontset)
{
struct cairographics2d *gr = NULL;
struct peerfont *pfont = NULL;
cairo_glyph_t *glyphs = NULL;
int *native_codes;
float *native_positions;
jint i = 0;
g_assert (java_codes != NULL);
g_assert (java_positions != NULL);
gr = JLONG_TO_PTR(struct cairographics2d, pointer);
g_assert (gr != NULL);
pfont = (struct peerfont *) gtkpeer_get_font(env, font);
g_assert (pfont != NULL);
glyphs = g_malloc( sizeof(cairo_glyph_t) * n);
g_assert (glyphs != NULL);
native_codes = (*env)->GetIntArrayElements (env, java_codes, NULL);
native_positions = (*env)->GetFloatArrayElements (env, java_positions, NULL);
/* Set up glyphs and layout */
for (i = 0; i < n; ++i)
{
glyphs[i].index = native_codes[i];
glyphs[i].x = x + native_positions[ 2*i ];
glyphs[i].y = y + native_positions[ 2*i + 1];
}
(*env)->ReleaseFloatArrayElements (env, java_positions, native_positions, 0);
(*env)->ReleaseIntArrayElements (env, java_codes, native_codes, 0);
/* Iterate through glyphs and draw */
jlong* fonts = (*env)->GetLongArrayElements (env, java_fontset, NULL);
gdk_threads_enter();
for (i = 0; i < n; i++)
{
PangoFcFont *font = JLONG_TO_PTR(PangoFcFont, fonts[i]);
/* Draw as many glyphs as possible with the current font */
int length = 0;
while (i < n-1 && fonts[i] == fonts[i+1])
{
length++;
i++;
}
FT_Face face = pango_fc_font_lock_face( font );
cairo_font_face_t *ft = cairo_ft_font_face_create_for_ft_face (face, 0);
g_assert (ft != NULL);
cairo_set_font_face (gr->cr, ft);
cairo_show_glyphs (gr->cr, &glyphs[i-length], length+1);
cairo_font_face_destroy (ft);
pango_fc_font_unlock_face(font);
}
gdk_threads_leave();
g_free(glyphs);
}
.. at end before g_free(glyphs) must be added:
...
gdk_threads_leave();
(*env)->ReleaseLongArrayElements (env, java_fontset, fonts, 0);
g_free(glyphs);
}
The diff is:
---
classpath-0.97.1/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c-org
2008-05-20 19:56:25.000000000 +0300
+++
classpath-0.97.1/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
2008-05-20 20:01:09.000000000 +0300
@@ -370,7 +370,8 @@
cairo_font_face_destroy (ft);
pango_fc_font_unlock_face(font);
}
- gdk_threads_leave();
+ gdk_threads_leave();
+ (*env)->ReleaseLongArrayElements (env, java_fontset, fonts, 0);
g_free(glyphs);
}
BR,
Assen Stoyanov
--
Summary: Memory Leak in gtk-peer
CairoGraphics2D.cairoDrawGlyphVector native function
(classpath 0.97.1)
Product: classpath
Version: 0.97
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: awt
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: softa at ttechgroup dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36289
- [Bug awt/36289] New: Memory Leak in gtk-peer CairoGraphics2D.cairoDrawGlyphVector native function (classpath 0.97.1),
softa at ttechgroup dot com <=