aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni/BluetoothManager.cxx
diff options
context:
space:
mode:
authorPetre Eftime <[email protected]>2016-03-07 18:24:06 +0200
committerPetre Eftime <[email protected]>2016-03-07 18:24:06 +0200
commit09bbf2268bebbd49a5a5be05e3511212959f0440 (patch)
tree11934b9085b680e50933aca37ed3326b9570a0c1 /java/jni/BluetoothManager.cxx
parent82f302d576d772277b6bcfb08d034047e10bb753 (diff)
jni: clean up allocated strings after getObject_setter
Signed-off-by: Petre Eftime <[email protected]>
Diffstat (limited to 'java/jni/BluetoothManager.cxx')
-rw-r--r--java/jni/BluetoothManager.cxx12
1 files changed, 12 insertions, 0 deletions
diff --git a/java/jni/BluetoothManager.cxx b/java/jni/BluetoothManager.cxx
index a3257d8..52b0557 100644
--- a/java/jni/BluetoothManager.cxx
+++ b/java/jni/BluetoothManager.cxx
@@ -73,6 +73,15 @@ static void getObject_setter(JNIEnv *env,
}
}
+static void getObject_cleaner(std::string *name_to_write, std::string *identifier_to_write)
+{
+ if (name_to_write != nullptr)
+ delete name_to_write;
+
+ if (identifier_to_write != nullptr)
+ delete identifier_to_write;
+}
+
jobject Java_tinyb_BluetoothManager_find(JNIEnv *env, jobject obj, jint type,
jstring name, jstring identifier, jobject parent,
jlong milliseconds)
@@ -93,6 +102,7 @@ jobject Java_tinyb_BluetoothManager_find(JNIEnv *env, jobject obj, jint type,
identifier_to_write,
b_parent,
std::chrono::milliseconds(milliseconds));
+ getObject_cleaner(name_to_write, identifier_to_write);
BluetoothObject *b_object_naked = b_object.release();
if (!b_object_naked)
@@ -127,6 +137,7 @@ jobject Java_tinyb_BluetoothManager_getObject(JNIEnv *env, jobject obj, jint typ
std::unique_ptr<BluetoothObject> b_object = manager->get_object(b_type, name_to_write,
identifier_to_write,
b_parent);
+ getObject_cleaner(name_to_write, identifier_to_write);
BluetoothObject *b_object_naked = b_object.release();
if (!b_object_naked)
@@ -159,6 +170,7 @@ jobject Java_tinyb_BluetoothManager_getObjects(JNIEnv *env, jobject obj, jint ty
name_to_write,
identifier_to_write,
b_parent);
+ getObject_cleaner(name_to_write, identifier_to_write);
jobject result = convert_vector_to_jobject<BluetoothObject>(env, array, "(J)V");
return result;
}