Commit ec911818 authored by George Nash's avatar George Nash

Clear the jni_callbacks list on shutdown

This will release all global refs held in the jni_callbacks
list.

Change-Id: Ia35e99aa8fbdc9e3d47360b5bb59c2d4872d69fd
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent 4dfefbae
......@@ -370,6 +370,26 @@ jni_list_remove(jni_callback_data *item)
OC_DBG("JNI: - unlock %s\n", __func__);
}
void
jni_list_clear()
{
OC_DBG("JNI: - lock %s\n", __func__);
jni_mutex_lock(jni_sync_lock);
jint getEnvResult = 0;
JNIEnv *jenv = get_jni_env(&getEnvResult);
jni_callback_data *item = jni_list_get_head();
while (item) {
JCALL1(DeleteGlobalRef, jenv, item->jcb_obj);
oc_list_remove(jni_callbacks, item);
free(item);
item = NULL;
item = jni_list_get_head();
}
release_jni_env(getEnvResult);
jni_mutex_unlock(jni_sync_lock);
OC_DBG("JNI: - unlock %s\n", __func__);
}
jni_callback_data *
jni_list_get_item_by_java_callback(jobject callback)
{
......
......@@ -179,6 +179,7 @@ typedef struct jni_callback_data_s {
jni_callback_data * jni_list_get_head();
void jni_list_add(jni_callback_data *item);
void jni_list_remove(jni_callback_data *item);
void jni_list_clear();
jni_callback_data *jni_list_get_item_by_java_callback(jobject callback);
jni_callback_data *jni_list_get_item_by_callback_valid(
jni_callback_valid_t cb_valid);
......
......@@ -243,6 +243,7 @@ int jni_main_init(const oc_handler_t *handler)
#elif defined(__linux__)
pthread_join(jni_poll_event_thread, NULL);
#endif
jni_list_clear();
}
%}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment