X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fjava.c;h=ee14373ed9f75485a91b9dc3b93283f8e4eafcd9;hb=ab2e3c958d3fed41438a8b3c2d0cca21b1bca56f;hp=b69ca946b301c36a367c114e98666c7b33e69acd;hpb=cc0bb2b472628ccede974a02c822d1f9189f0d21;p=collectd.git diff --git a/src/java.c b/src/java.c index b69ca946..ee14373e 100644 --- a/src/java.c +++ b/src/java.c @@ -906,7 +906,7 @@ static jobject ctoj_notification (JNIEnv *jvm_env, /* {{{ */ #undef SET_STRING /* Set the `time' member. Java stores time in milliseconds. */ - status = ctoj_long (jvm_env, ((jlong) n->time) * ((jlong) 1000), + status = ctoj_long (jvm_env, (jlong) CDTIME_T_TO_MS (n->time), c_notification, o_notification, "setTime"); if (status != 0) { @@ -1306,7 +1306,7 @@ static int jtoc_notification (JNIEnv *jvm_env, notification_t *n, /* {{{ */ return (-1); } /* Java measures time in milliseconds. */ - n->time = (time_t) (tmp_long / ((jlong) 1000)); + n->time = MS_TO_CDTIME_T(tmp_long); status = jtoc_int (jvm_env, &tmp_int, class_ptr, object_ptr, "getSeverity"); @@ -1790,6 +1790,7 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{ pthread_mutex_unlock (&java_callbacks_lock); ERROR ("java plugin: cjni_callback_info_create: strdup failed."); (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name); + sfree (cbi); return (NULL); } @@ -1799,7 +1800,8 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{ if (cbi->object == NULL) { ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed."); - free (cbi); + sfree (cbi->name); + sfree (cbi); return (NULL); } @@ -1807,7 +1809,9 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{ if (cbi->class == NULL) { ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed."); - free (cbi); + (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object); + sfree (cbi->name); + sfree (cbi); return (NULL); } @@ -1818,7 +1822,9 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{ ERROR ("java plugin: cjni_callback_info_create: " "Cannot find the `%s' method with signature `%s'.", method_name, method_signature); - free (cbi); + (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object); + sfree (cbi->name); + sfree (cbi); return (NULL); } @@ -2115,7 +2121,7 @@ static int cjni_thread_detach (void) /* {{{ */ 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) /* {{{ */ { @@ -2468,7 +2474,6 @@ static int cjni_read (user_data_t *ud) /* {{{ */ { JNIEnv *jvm_env; cjni_callback_info_t *cbi; - int status; int ret_status; if (jvm == NULL) @@ -2492,13 +2497,7 @@ static int cjni_read (user_data_t *ud) /* {{{ */ 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 +2508,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 +2532,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 +2541,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 */ @@ -2560,7 +2553,6 @@ static int cjni_flush (cdtime_t timeout, const char *identifier, /* {{{ */ cjni_callback_info_t *cbi; jobject o_timeout; jobject o_identifier; - int status; int ret_status; if (jvm == NULL) @@ -2587,6 +2579,7 @@ static int cjni_flush (cdtime_t timeout, const char *identifier, /* {{{ */ { ERROR ("java plugin: cjni_flush: Converting double " "to Number object failed."); + cjni_thread_detach (); return (-1); } @@ -2598,6 +2591,7 @@ static int cjni_flush (cdtime_t timeout, const char *identifier, /* {{{ */ { (*jvm_env)->DeleteLocalRef (jvm_env, o_timeout); ERROR ("java plugin: cjni_flush: NewStringUTF failed."); + cjni_thread_detach (); return (-1); } } @@ -2608,13 +2602,7 @@ static int cjni_flush (cdtime_t timeout, const char *identifier, /* {{{ */ (*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 */ @@ -2640,7 +2628,10 @@ static void cjni_log (int severity, const char *message, /* {{{ */ 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); @@ -2658,7 +2649,6 @@ static int cjni_notification (const notification_t *n, /* {{{ */ JNIEnv *jvm_env; cjni_callback_info_t *cbi; jobject o_notification; - int status; int ret_status; if (jvm == NULL) @@ -2683,6 +2673,7 @@ static int cjni_notification (const notification_t *n, /* {{{ */ if (o_notification == NULL) { ERROR ("java plugin: cjni_notification: ctoj_notification failed."); + cjni_thread_detach (); return (-1); } @@ -2691,13 +2682,7 @@ static int cjni_notification (const notification_t *n, /* {{{ */ (*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 */ @@ -2725,24 +2710,20 @@ static int cjni_match_target_create (const oconfig_item_t *ci, /* {{{ */ (*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) @@ -2936,10 +2917,7 @@ static int cjni_match_target_invoke (const data_set_t *ds, /* {{{ */ } } /* 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 */ @@ -3079,10 +3057,8 @@ static int cjni_init (void) /* {{{ */ if (config_block != NULL) { - cjni_config_perform (config_block); oconfig_free (config_block); - config_block = NULL; } if (jvm == NULL)