OSDN Git Service

Wrap reference count to one module
authorjiangmin <jiangming.wu@intel.com>
Wed, 6 Jan 2016 02:40:12 +0000 (10:40 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 20 Jul 2016 09:53:23 +0000 (17:53 +0800)
The reference count should be not managed by two module
(PdfRenderer and PdfEditor) separately.
It will cause memory leak and crash.
FPDF_InitLibrary will be call twice and excute
"g_FPDFAPI_pDefaultMgr = new CPDF_ModuleMgr;" twice.
Memory leak will happen.
PdfEditor will call FPDF_DestroyLibrary just after
PdfRenderer calls FPDF_InitLibrary. PdfRenderer
will execute FPDF's API and crash for null point of
CPDF_ModuleMgr::Get() due to PdfEditor's calling for
FPDF_DestroyLibrary.
So we merge the reference count of FPDF library to
PdfLibrary.cpp from PdfEditor.cpp and PdfRenderer.cpp.

Change-Id: I984a268ddd2d6d97e086e51d6459751feeaf372a
Signed-off-by: Wu Jiangming <jiangmin.wu@intel.com>
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-15089
Reviewed-on: https://android.intel.com:443/455409

core/jni/Android.mk
core/jni/android/graphics/pdf/PdfEditor.cpp
core/jni/android/graphics/pdf/PdfLibrary.cpp [new file with mode: 0644]
core/jni/android/graphics/pdf/PdfRenderer.cpp

index 86c1918..dbc0ed5 100644 (file)
@@ -139,6 +139,7 @@ LOCAL_SRC_FILES:= \
     android/graphics/Xfermode.cpp \
     android/graphics/YuvToJpegEncoder.cpp \
     android/graphics/pdf/PdfDocument.cpp \
+    android/graphics/pdf/PdfLibrary.cpp \
     android/graphics/pdf/PdfEditor.cpp \
     android/graphics/pdf/PdfRenderer.cpp \
     android_media_AudioRecord.cpp \
index 52b69e0..cfe7155 100644 (file)
@@ -51,25 +51,9 @@ static struct {
     jfieldID bottom;
 } gRectClassInfo;
 
-static Mutex sLock;
+extern void initializeLibraryIfNeeded();
 
-static int sUnmatchedInitRequestCount = 0;
-
-static void initializeLibraryIfNeeded() {
-    Mutex::Autolock _l(sLock);
-    if (sUnmatchedInitRequestCount == 0) {
-        FPDF_InitLibrary();
-    }
-    sUnmatchedInitRequestCount++;
-}
-
-static void destroyLibraryIfNeeded() {
-    Mutex::Autolock _l(sLock);
-    sUnmatchedInitRequestCount--;
-    if (sUnmatchedInitRequestCount == 0) {
-       FPDF_DestroyLibrary();
-    }
-}
+extern void destroyLibraryIfNeeded();
 
 static int getBlock(void* param, unsigned long position, unsigned char* outBuffer,
         unsigned long size) {
diff --git a/core/jni/android/graphics/pdf/PdfLibrary.cpp b/core/jni/android/graphics/pdf/PdfLibrary.cpp
new file mode 100644 (file)
index 0000000..2f94e00
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015 Intel iCDG
+ *
+ * Move the reference count of fpdfview in PdfRenderer.cpp and PdfEditor.cpp
+ * to PdfLibrary.cpp
+ *
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include "fpdfview.h"
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
+#include "fsdk_rendercontext.h"
+#pragma GCC diagnostic pop
+
+#include "core_jni_helpers.h"
+#include <vector>
+#include <unistd.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+namespace android {
+
+static Mutex sLock;
+
+static int sUnmatchedInitRequestCount = 0;
+
+void initializeLibraryIfNeeded() {
+    Mutex::Autolock _l(sLock);
+    if (sUnmatchedInitRequestCount == 0) {
+        FPDF_InitLibrary();
+    }
+    sUnmatchedInitRequestCount++;
+}
+
+void destroyLibraryIfNeeded() {
+    Mutex::Autolock _l(sLock);
+    sUnmatchedInitRequestCount--;
+    if (sUnmatchedInitRequestCount == 0) {
+       FPDF_DestroyLibrary();
+    }
+}
+
+};
index 006eef8..a23cc58 100644 (file)
@@ -43,25 +43,9 @@ static struct {
     jfieldID y;
 } gPointClassInfo;
 
-static Mutex sLock;
+extern void initializeLibraryIfNeeded();
 
-static int sUnmatchedInitRequestCount = 0;
-
-static void initializeLibraryIfNeeded() {
-    Mutex::Autolock _l(sLock);
-    if (sUnmatchedInitRequestCount == 0) {
-        FPDF_InitLibrary();
-    }
-    sUnmatchedInitRequestCount++;
-}
-
-static void destroyLibraryIfNeeded() {
-    Mutex::Autolock _l(sLock);
-    sUnmatchedInitRequestCount--;
-    if (sUnmatchedInitRequestCount == 0) {
-       FPDF_DestroyLibrary();
-    }
-}
+extern void destroyLibraryIfNeeded();
 
 static int getBlock(void* param, unsigned long position, unsigned char* outBuffer,
         unsigned long size) {