Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: jni/JniFilterEngine.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Removed a Log.d Created Jan. 22, 2015, 6:56 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jni/JniFilterChangeCallback.cpp ('k') | jni/JniJsValue.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/JniFilterEngine.cpp
diff --git a/jni/JniFilterEngine.cpp b/jni/JniFilterEngine.cpp
index 7976902711d9e59dd5038bce35cea432d6b40876..07adbb873636eb12dc398eeeaf2a39e99735c118 100644
--- a/jni/JniFilterEngine.cpp
+++ b/jni/JniFilterEngine.cpp
@@ -34,11 +34,11 @@ static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector<AdblockPlus::Su
static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
jobject jContentType)
{
- jclass contentTypeClass = env->GetObjectClass(jContentType);
- jmethodID nameMethod = env->GetMethodID(contentTypeClass, "name",
+ JniLocalReference<jclass> contentTypeClass(env, env->GetObjectClass(jContentType));
+ jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name",
"()Ljava/lang/String;");
- jstring jValue = (jstring) env->CallObjectMethod(jContentType, nameMethod);
- const std::string value = JniJavaToStdString(env, jValue);
+ JniLocalReference<jstring> jValue(env, (jstring) env->CallObjectMethod(jContentType, nameMethod));
+ const std::string value = JniJavaToStdString(env, *jValue);
return AdblockPlus::FilterEngine::StringToContentType(value);
}
@@ -94,7 +94,7 @@ static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr)
for (std::vector<AdblockPlus::FilterPtr>::iterator it = filters.begin(), end = filters.end(); it != end; it++)
{
- JniAddObjectToList(env, list, NewJniFilter(env, *it));
+ JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilter(env, *it)));
}
return list;
@@ -234,7 +234,7 @@ static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, j
for (std::vector<std::string>::iterator it = selectors.begin(), end = selectors.end(); it != end; it++)
{
- JniAddObjectToList(env, list, env->NewStringUTF(it->c_str()));
+ JniAddObjectToList(env, list, *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str())));
}
return list;
@@ -274,7 +274,8 @@ static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, jstr
for (jsize i = 0; i < len; i++)
{
- documentUrls.push_back(JniJavaToStdString(env, static_cast<jstring>(env->GetObjectArrayElement(jDocumentUrls, i))));
+ documentUrls.push_back(JniJavaToStdString(env,
+ *JniLocalReference<jstring>(env, static_cast<jstring>(env->GetObjectArrayElement(jDocumentUrls, i)))));
}
try
« no previous file with comments | « jni/JniFilterChangeCallback.cpp ('k') | jni/JniJsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld