diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp index 3de2c9509ab78..716d96044e3ea 100644 --- a/core/jni/android/graphics/TextLayout.cpp +++ b/core/jni/android/graphics/TextLayout.cpp @@ -151,7 +151,7 @@ jint TextLayout::layoutLine(const jchar* text, jint len, jint flags, int &dir, j } bool TextLayout::prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags, - const jchar** outText, int32_t* outBytes) { + const jchar** outText, int32_t* outBytes, jchar** outBuffer) { const jchar *workText = text; jchar *buffer = NULL; int dir = kDirection_LTR; @@ -196,8 +196,8 @@ bool TextLayout::prepareText(SkPaint *paint, const jchar* text, jsize len, jint *outBytes = (workLimit - workText) << 1; *outText = workText; - - free(buffer); + *outBuffer = buffer; + return true; } @@ -207,8 +207,9 @@ bool TextLayout::prepareText(SkPaint *paint, const jchar* text, jsize len, jint void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags, jfloat x, jfloat y,SkCanvas *canvas, SkPath *path) { const jchar *workText; + jchar *buffer = NULL; int32_t workBytes; - if (prepareText(paint, text, len, bidiFlags, &workText, &workBytes)) { + if (prepareText(paint, text, len, bidiFlags, &workText, &workBytes, &buffer)) { SkScalar x_ = SkFloatToScalar(x); SkScalar y_ = SkFloatToScalar(y); if (canvas) { @@ -216,6 +217,7 @@ void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len, } else { paint->getTextPath(workText, workBytes, x_, y_, path); } + free(buffer); } } diff --git a/core/jni/android/graphics/TextLayout.h b/core/jni/android/graphics/TextLayout.h index dc7208af0a820..3d05e18f5e1cc 100644 --- a/core/jni/android/graphics/TextLayout.h +++ b/core/jni/android/graphics/TextLayout.h @@ -65,7 +65,7 @@ public: SkPath* path, SkCanvas* canvas); static bool prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags, - const jchar** outText, int32_t* outBytes); + const jchar** outText, int32_t* outBytes, jchar** outBuffer); private: static bool needsLayout(const jchar* text, jint len, jint bidiFlags); diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index d2e7faf6f6061..1e4a66d74a920 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -256,9 +256,11 @@ static void android_view_GLES20Canvas_setupLinearShader(JNIEnv* env, jobject can static void renderText(OpenGLRenderer* renderer, const jchar* text, int count, jfloat x, jfloat y, int flags, SkPaint* paint) { const jchar *workText; + jchar* buffer = NULL; int32_t workBytes; - if (TextLayout::prepareText(paint, text, count, flags, &workText, &workBytes)) { + if (TextLayout::prepareText(paint, text, count, flags, &workText, &workBytes, &buffer)) { renderer->drawText((const char*) workText, workBytes, count, x, y, paint); + free(buffer); } }