Skip to content

Commit 3314922

Browse files
authored
Release JNI string chars after use (#327)
1 parent e0469f4 commit 3314922

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/src/main/cpp/https-bloom-lib.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Java_com_duckduckgo_app_httpsupgrade_BloomFilter_createBloomFilterFromFile(JNIEn
2424
const char *pathChars = env->GetStringUTFChars(path, &isElementCopy);
2525

2626
BloomFilter* filter = new BloomFilter(pathChars, maxItems);
27+
env->ReleaseStringUTFChars(path, pathChars);
2728
return (long) filter;
2829
}
2930

@@ -50,6 +51,8 @@ Java_com_duckduckgo_app_httpsupgrade_BloomFilter_add(JNIEnv *env,
5051

5152
BloomFilter *filter = (BloomFilter *) pointer;
5253
filter->add(elementChars);
54+
55+
env->ReleaseStringUTFChars(element, elementChars);
5356
}
5457

5558
extern "C"
@@ -63,5 +66,7 @@ Java_com_duckduckgo_app_httpsupgrade_BloomFilter_contains(JNIEnv *env,
6366
const char *elementChars = env->GetStringUTFChars(element, &isElementCopy);
6467

6568
BloomFilter *filter = (BloomFilter *) pointer;
66-
return filter->contains(elementChars);
69+
bool containsElement = filter->contains(elementChars);
70+
env->ReleaseStringUTFChars(element, elementChars);
71+
return containsElement;
6772
}

0 commit comments

Comments
 (0)