Skip to content
Browse files

properly release local string references

caused crash when loops got deep comparing strings inside json key
fixes #39
  • Loading branch information...
1 parent 9f376c6 commit 01f13ea8640ce9c68c827a6ff3d01f9d4f3d0977 @mschoch mschoch committed Jun 29, 2012
View
31 TouchDB-Android-TestApp/src/com/couchbase/touchdb/testapp/tests/Views.java
@@ -129,6 +129,20 @@ private TDRevision putDoc(TDDatabase db, Map<String,Object> props) {
return result;
}
+ public void putNDocs(TDDatabase db, int n) {
+ for(int i=0; i< n; i++) {
+ Map<String,Object> doc = new HashMap<String,Object>();
+ doc.put("_id", String.format("%d", i));
+ List<String> key = new ArrayList<String>();
+ for(int j=0; j< 256; j++) {
+ key.add("key");
+ }
+ key.add(String.format("key-%d", i));
+ doc.put("key", key);
+ putDoc(db, doc);
+ }
+ }
+
public static TDView createView(TDDatabase db) {
TDView view = db.getViewNamed("aview");
view.setMapReduceBlocks(new TDViewMapBlock() {
@@ -958,4 +972,21 @@ public void map(Map<String, Object> document, TDViewMapEmitBlock emitter) {
db.close();
}
+ public void testLargerViewQuery() {
+
+ String filesDir = getContext().getFilesDir().getAbsolutePath();
+
+ TDDatabase db = TDDatabase.createEmptyDBAtPath(filesDir + "/touch_couch_test.sqlite3");
+ putNDocs(db, 4);
+ TDView view = createView(db);
+
+ TDStatus updated = view.updateIndex();
+ Assert.assertEquals(TDStatus.OK, updated.getCode());
+
+ // Query all rows:
+ TDQueryOptions options = new TDQueryOptions();
+ TDStatus status = new TDStatus();
+ List<Map<String, Object>> rows = view.queryWithOptions(options, status);
+ }
+
}
View
2 TouchDB-Android/jni/com_couchbase_touchdb_TDCollateJSON.cpp
@@ -259,6 +259,8 @@ static int compareStringsUnicode(const char** in1, const char** in2) {
JNIEnv *env = getEnv();
int result = env->CallStaticIntMethod(TDCollateJSONClass, compareMethod,
str1, str2);
+ env->DeleteLocalRef(str1);
+ env->DeleteLocalRef(str2);
return result;
}
View
BIN TouchDB-Android/libs/armeabi/libcom_couchbase_touchdb_TDCollateJSON.so
Binary file not shown.
View
BIN TouchDB-Android/obj/local/armeabi/libcom_couchbase_touchdb_TDCollateJSON.so
Binary file not shown.
View
BIN ...al/armeabi/objs/com_couchbase_touchdb_TDCollateJSON/com_couchbase_touchdb_TDCollateJSON.o
Binary file not shown.

0 comments on commit 01f13ea

Please sign in to comment.
Something went wrong with that request. Please try again.