From 86460a7cd07ff1d3097595fad8fc03780c8bf86c Mon Sep 17 00:00:00 2001 From: Jeffrey Liu Date: Fri, 4 Jun 2021 21:49:43 -0700 Subject: [PATCH] 1.0.2 fix memory leak --- README.md | 2 +- app/build.gradle | 2 +- floydsteinbergdithering/src/main/cpp/fsdither.cpp | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0538a6e..e9f477b 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Using FSD ##### Dependencies ```groovy dependencies { - compile 'com.github.jeffreyliu8:Native-Floyd-Steinberg-Dithering:1.0.1' + compile 'com.github.jeffreyliu8:Native-Floyd-Steinberg-Dithering:1.0.2' } ``` diff --git a/app/build.gradle b/app/build.gradle index 27d0245..eeb43a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,5 +39,5 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' // implementation project(":floydsteinbergdithering") - implementation 'com.github.jeffreyliu8:Native-Floyd-Steinberg-Dithering:1.0.1' + implementation 'com.github.jeffreyliu8:Native-Floyd-Steinberg-Dithering:1.0.2' } diff --git a/floydsteinbergdithering/src/main/cpp/fsdither.cpp b/floydsteinbergdithering/src/main/cpp/fsdither.cpp index 5b39dba..0920002 100644 --- a/floydsteinbergdithering/src/main/cpp/fsdither.cpp +++ b/floydsteinbergdithering/src/main/cpp/fsdither.cpp @@ -63,7 +63,7 @@ static void floydSteinberg(AndroidBitmapInfo *info, void *pixels) { // set the new pixel back in line[x] = newpixel; - int err = oldpixel - newpixel; + int err = (int)(oldpixel - newpixel); if (x + 1 < w) d[y][x + 1] = d[y][x + 1] + (int) (err * (7. / 16)); @@ -77,6 +77,13 @@ static void floydSteinberg(AndroidBitmapInfo *info, void *pixels) { pixels = (char *) pixels + info->stride; } + + //Free each sub-array + for (int i = 0; i < info->height; ++i) { + delete[] d[i]; + } + //Free the array of pointers + delete[] d; } static void global_mono(AndroidBitmapInfo *info, void *pixels) {