Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 77920de

Browse files
committed
Fixed: Memory is not released at some points in UTF16String
1 parent 6c95b2e commit 77920de

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

android-tree-sitter/src/main/cpp/ts_tree.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_com_itsaky_androidide_treesitter_
5050
uint32_t count;
5151
TSRange *ranges = ts_tree_get_changed_ranges((TSTree*) oldTree, (TSTree*) tree, &count);
5252
if (count == 0) {
53-
return NULL;
53+
return nullptr;
5454
}
5555

5656
jclass klass = env->FindClass("com/itsaky/androidide/treesitter/TSRange");
57-
jobjectArray arr = env->NewObjectArray(count, klass, NULL);
57+
jobjectArray arr = env->NewObjectArray(count, klass, nullptr);
5858
for (uint32_t i = 0; i < count; i++) {
5959
TSRange *r = (ranges + i);
6060
env->SetObjectArrayElement(arr, i, _marshalRange(env, *r));

android-tree-sitter/src/main/cpp/utf16str/UTF16String.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ UTF16String *UTF16String::append(JNIEnv *env, jstring src, jint from, jint len)
9090
auto c = *(chars + i);
9191
append(c);
9292
}
93+
FNI_ReleaseStringChars(chars);
9394
return this;
9495
}
9596

@@ -113,7 +114,8 @@ UTF16String *UTF16String::insert(JNIEnv *env, jstring src, jint index) {
113114
insert(index + i, c);
114115
}
115116

116-
cout << endl;
117+
FNI_ReleaseStringChars(chars);
118+
117119
return this;
118120
}
119121

@@ -153,6 +155,9 @@ UTF16String *UTF16String::replace_bytes(JNIEnv *env, jint start, jint end, jstri
153155
delete_bytes(i, end);
154156
}
155157

158+
FNI_ReleaseStringChars(chars);
159+
delete [] bytes;
160+
156161
return this;
157162
}
158163

0 commit comments

Comments
 (0)