Clean reader/searcher objects properly

This commit is contained in:
Kelson 2016-10-14 19:46:08 +02:00
parent 04e6252d5f
commit fe2ea926a3

View File

@ -241,9 +241,11 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_loadZIM(JNIEnv *e
pthread_mutex_lock(&readerLock);
try {
if (reader != NULL) delete reader;
reader = new kiwix::Reader(cPath);
} catch (exception &e) {
std::cerr << e.what() << std::endl;
reader = NULL;
retVal = JNI_FALSE;
}
pthread_mutex_unlock(&readerLock);
@ -423,10 +425,13 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_loadFulltextIndex
std::string cPath = jni2c(path, env);
pthread_mutex_lock(&searcherLock);
searcher = NULL;
try {
if (searcher != NULL) delete searcher;
searcher = new kiwix::XapianSearcher(cPath);
} catch (exception &e) {
std::cerr << e.what() << std::endl;
searcher = NULL;
retVal = JNI_FALSE;
}
pthread_mutex_unlock(&searcherLock);