@@ -60,6 +60,9 @@ class DocumentFile {
60
60
public:
61
61
FPDF_DOCUMENT pdfDocument = nullptr ;
62
62
63
+ public:
64
+ jbyte *cDataCopy = NULL ;
65
+
63
66
DocumentFile () { initLibraryIfNeed (); }
64
67
~DocumentFile ();
65
68
};
@@ -69,7 +72,10 @@ DocumentFile::~DocumentFile(){
69
72
FPDF_CloseDocument (pdfDocument);
70
73
pdfDocument = nullptr ;
71
74
}
72
-
75
+ if (cDataCopy != NULL ){
76
+ free (cDataCopy);
77
+ cDataCopy = NULL ;
78
+ }
73
79
destroyLibraryIfNeed ();
74
80
}
75
81
@@ -277,13 +283,11 @@ Java_io_legere_pdfiumandroid_PdfiumCore_nativeOpenMemDocument(JNIEnv *env, jobje
277
283
cpassword = env->GetStringUTFChars (password, nullptr );
278
284
}
279
285
280
- jbyte *cData = env->GetByteArrayElements (data, nullptr );
281
286
int size = (int ) env->GetArrayLength (data);
282
287
auto *cDataCopy = new jbyte[size];
283
- memcpy (cDataCopy, cData , size);
288
+ env-> GetByteArrayRegion (data, 0 , size, cDataCopy );
284
289
FPDF_DOCUMENT document = FPDF_LoadMemDocument ( reinterpret_cast <const void *>(cDataCopy),
285
290
size, cpassword);
286
- env->ReleaseByteArrayElements (data, cData, JNI_ABORT);
287
291
288
292
if (cpassword != nullptr ) {
289
293
env->ReleaseStringUTFChars (password, cpassword);
@@ -308,7 +312,7 @@ Java_io_legere_pdfiumandroid_PdfiumCore_nativeOpenMemDocument(JNIEnv *env, jobje
308
312
}
309
313
310
314
docFile->pdfDocument = document;
311
-
315
+ docFile-> cDataCopy = cDataCopy;
312
316
return reinterpret_cast <jlong>(docFile);
313
317
}
314
318
0 commit comments