summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b14c25d)
raw | patch | inline | side by side (parent: b14c25d)
author | Florian Forster <octo@google.com> | |
Thu, 28 Aug 2014 18:41:25 +0000 (20:41 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 29 Aug 2014 05:02:18 +0000 (07:02 +0200) |
Each call to cjni_thread_attach() much be accompanied by
a call to cjni_thread_detach(). Some error handling cases were missing
the call, potentially locking the plugin up.
a call to cjni_thread_detach(). Some error handling cases were missing
the call, potentially locking the plugin up.
src/java.c | patch | blob | history |
diff --git a/src/java.c b/src/java.c
index ee503550bda2840a1fa6bdd465e2a11abca68642..83cd353f0e1f6a06667c35b474467207f02b92f9 100644 (file)
--- a/src/java.c
+++ b/src/java.c
cjni_env->jvm_env = NULL;
return (0);
-} /* }}} JNIEnv *cjni_thread_attach */
+} /* }}} int cjni_thread_detach */
static int cjni_config_add_jvm_arg (oconfig_item_t *ci) /* {{{ */
{
{
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
- int status;
int ret_status;
if (jvm == NULL)
ret_status = (*jvm_env)->CallIntMethod (jvm_env, cbi->object,
cbi->method);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_read: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_read */
@@ -2509,7 +2502,6 @@ static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
jobject vl_java;
- int status;
int ret_status;
if (jvm == NULL)
@@ -2534,6 +2526,7 @@ static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
if (vl_java == NULL)
{
ERROR ("java plugin: cjni_write: ctoj_value_list failed.");
+ cjni_thread_detach ();
return (-1);
}
@@ -2542,13 +2535,7 @@ static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
(*jvm_env)->DeleteLocalRef (jvm_env, vl_java);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_write: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_write */
cjni_callback_info_t *cbi;
jobject o_timeout;
jobject o_identifier;
- int status;
int ret_status;
if (jvm == NULL)
{
ERROR ("java plugin: cjni_flush: Converting double "
"to Number object failed.");
+ cjni_thread_detach ();
return (-1);
}
{
(*jvm_env)->DeleteLocalRef (jvm_env, o_timeout);
ERROR ("java plugin: cjni_flush: NewStringUTF failed.");
+ cjni_thread_detach ();
return (-1);
}
}
(*jvm_env)->DeleteLocalRef (jvm_env, o_identifier);
(*jvm_env)->DeleteLocalRef (jvm_env, o_timeout);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_flush: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_flush */
o_message = (*jvm_env)->NewStringUTF (jvm_env, message);
if (o_message == NULL)
+ {
+ cjni_thread_detach ();
return;
+ }
(*jvm_env)->CallVoidMethod (jvm_env,
cbi->object, cbi->method, (jint) severity, o_message);
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
jobject o_notification;
- int status;
int ret_status;
if (jvm == NULL)
if (o_notification == NULL)
{
ERROR ("java plugin: cjni_notification: ctoj_notification failed.");
+ cjni_thread_detach ();
return (-1);
}
(*jvm_env)->DeleteLocalRef (jvm_env, o_notification);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_read: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_notification */
(*jvm_env)->DeleteLocalRef (jvm_env, cbi_ret->object); \
} \
free (cbi_ret); \
- if (jvm_env != NULL) { \
- if (o_ci != NULL) \
- (*jvm_env)->DeleteLocalRef (jvm_env, o_ci); \
- cjni_thread_detach (); \
- } \
+ if (o_ci != NULL) \
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_ci); \
+ cjni_thread_detach (); \
return (status)
if (jvm == NULL)
{
ERROR ("java plugin: cjni_read: jvm == NULL");
- BAIL_OUT (-1);
+ return (-1);
}
jvm_env = cjni_thread_attach ();
if (jvm_env == NULL)
- {
- BAIL_OUT (-1);
- }
+ return (-1);
/* Find out whether to create a match or a target. */
if (strcasecmp ("Match", ci->key) == 0)
}
} /* if (cbi->type == CB_TYPE_TARGET) */
- status = cjni_thread_detach ();
- if (status != 0)
- ERROR ("java plugin: cjni_read: cjni_thread_detach failed.");
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_match_target_invoke */