Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/main/jni/src/mainJNILib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ class DocumentFile {
FPDF_DOCUMENT pdfDocument = NULL;
size_t fileSize;

public:
jbyte *cDataCopy = NULL;

DocumentFile() { initLibraryIfNeed(); }
~DocumentFile();
};
DocumentFile::~DocumentFile(){
if(pdfDocument != NULL){
FPDF_CloseDocument(pdfDocument);
}

if(cDataCopy != NULL){
free(cDataCopy);
cDataCopy = NULL;
}
destroyLibraryIfNeed();
}

Expand Down Expand Up @@ -238,13 +244,11 @@ JNI_FUNC(jlong, PdfiumCore, nativeOpenMemDocument)(JNI_ARGS, jbyteArray data, js
cpassword = env->GetStringUTFChars(password, NULL);
}

jbyte *cData = env->GetByteArrayElements(data, NULL);
int size = (int) env->GetArrayLength(data);
jbyte *cDataCopy = new jbyte[size];
memcpy(cDataCopy, cData, size);
env->GetByteArrayRegion(data, 0, size, cDataCopy);
FPDF_DOCUMENT document = FPDF_LoadMemDocument( reinterpret_cast<const void*>(cDataCopy),
size, cpassword);
env->ReleaseByteArrayElements(data, cData, JNI_ABORT);

if(cpassword != NULL) {
env->ReleaseStringUTFChars(password, cpassword);
Expand All @@ -269,7 +273,7 @@ JNI_FUNC(jlong, PdfiumCore, nativeOpenMemDocument)(JNI_ARGS, jbyteArray data, js
}

docFile->pdfDocument = document;

docFile->cDataCopy = cDataCopy;
return reinterpret_cast<jlong>(docFile);
}

Expand Down