File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323#include < string>
2424#include < vector>
2525#include < jni.h>
26+ #include < unistd.h>
27+ #include < sys/wait.h>
2628#include " pdf2htmlEX.h"
2729
2830// Creating char ** by hand is rather annoying.
@@ -92,10 +94,26 @@ Java_com_viliussutkus89_android_pdf2htmlex_pdf2htmlEX_call_1pdf2htmlEX(JNIEnv *e
9294
9395 int argc;
9496 char **argv;
95- int retVal;
97+ int retVal = -1 ;
98+
9699 vector_to_char_pp (args, &argc, &argv);
97100
98- retVal = pdf2htmlEX_main (argc, argv);
101+ // https://github.com/ViliusSutkus89/pdf2htmlEX-Android/issues/4
102+ // Upstream library is actually an executable, not a library.
103+ // May have some global state, initialized as static constructor, poisoned after first use.
104+ // Workaround: fork process before use.
105+ pid_t pid = fork ();
106+ if (0 == pid) {
107+ retVal = pdf2htmlEX_main (argc, argv);
108+ exit (retVal);
109+ }
110+ else if (0 < pid) {
111+ int wstatus;
112+ waitpid (pid, &wstatus, 0 );
113+ if (WIFEXITED (wstatus)) {
114+ retVal = WEXITSTATUS (wstatus);
115+ }
116+ }
99117
100118 for (int i = 0 ; i < argc; i++) {
101119 delete[] argv[i];
You can’t perform that action at this time.
0 commit comments