X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fjava.c;h=33d0504c129e7aebd23e08c93efc0ad27470ce07;hb=5afde1077e3c8fc119b79caa2572cbf84dbfe5ca;hp=6b92f54e966f313e907514d17569aed104312f1c;hpb=a82395b57384541152423862bcf44c0db7789641;p=collectd.git diff --git a/src/java.c b/src/java.c index 6b92f54e..33d0504c 100644 --- a/src/java.c +++ b/src/java.c @@ -26,7 +26,6 @@ #include "common.h" #include "filter_chain.h" -#include #include #if !defined(JNI_VERSION_1_2) @@ -1364,12 +1363,9 @@ static jint JNICALL cjni_api_dispatch_values (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_dispatch_notification (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_notification) { - notification_t n; + notification_t n = { 0 }; int status; - memset (&n, 0, sizeof (n)); - n.meta = NULL; - status = jtoc_notification (jvm_env, &n, o_notification); if (status != 0) { @@ -1424,7 +1420,7 @@ static jint JNICALL cjni_api_register_init (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_read) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_read, CB_TYPE_READ); @@ -1433,7 +1429,6 @@ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new read callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1448,7 +1443,7 @@ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_write) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_write, CB_TYPE_WRITE); @@ -1457,7 +1452,6 @@ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new write callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1471,7 +1465,7 @@ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_flush) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_flush, CB_TYPE_FLUSH); @@ -1480,7 +1474,6 @@ static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new flush callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1501,7 +1494,7 @@ static jint JNICALL cjni_api_register_shutdown (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_log) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_log, CB_TYPE_LOG); @@ -1510,7 +1503,6 @@ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new log callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1524,7 +1516,7 @@ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_notification) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_notification, @@ -1534,7 +1526,6 @@ static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new notification callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1568,9 +1559,8 @@ static jint JNICALL cjni_api_register_match_target (JNIEnv *jvm_env, /* {{{ */ if (type == CB_TYPE_MATCH) { - match_proc_t m_proc; + match_proc_t m_proc = { 0 }; - memset (&m_proc, 0, sizeof (m_proc)); m_proc.create = cjni_match_target_create; m_proc.destroy = cjni_match_target_destroy; m_proc.match = (void *) cjni_match_target_invoke; @@ -1579,9 +1569,8 @@ static jint JNICALL cjni_api_register_match_target (JNIEnv *jvm_env, /* {{{ */ } else if (type == CB_TYPE_TARGET) { - target_proc_t t_proc; + target_proc_t t_proc = { 0 }; - memset (&t_proc, 0, sizeof (t_proc)); t_proc.create = cjni_match_target_create; t_proc.destroy = cjni_match_target_destroy; t_proc.invoke = cjni_match_target_invoke; @@ -1801,14 +1790,13 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{ return (NULL); } - cbi = (cjni_callback_info_t *) malloc (sizeof (*cbi)); + cbi = calloc (1, sizeof (*cbi)); if (cbi == NULL) { - ERROR ("java plugin: cjni_callback_info_create: malloc failed."); + ERROR ("java plugin: cjni_callback_info_create: calloc failed."); (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name); return (NULL); } - memset (cbi, 0, sizeof (*cbi)); cbi->type = type; cbi->name = strdup (c_name); @@ -1906,7 +1894,7 @@ static int cjni_callback_register (JNIEnv *jvm_env, /* {{{ */ pthread_mutex_lock (&java_callbacks_lock); - tmp = (cjni_callback_info_t *) realloc (java_callbacks, + tmp = realloc (java_callbacks, (java_callbacks_num + 1) * sizeof (*java_callbacks)); if (tmp == NULL) { @@ -1987,7 +1975,7 @@ static int cjni_init_native (JNIEnv *jvm_env) /* {{{ */ static int cjni_create_jvm (void) /* {{{ */ { JNIEnv *jvm_env; - JavaVMInitArgs vm_args; + JavaVMInitArgs vm_args = { 0 }; JavaVMOption vm_options[jvm_argc]; int status; @@ -2006,7 +1994,6 @@ static int cjni_create_jvm (void) /* {{{ */ jvm_env = NULL; - memset (&vm_args, 0, sizeof (vm_args)); vm_args.version = JNI_VERSION_1_2; vm_args.options = vm_options; vm_args.nOptions = (jint) jvm_argc; @@ -2067,13 +2054,12 @@ static JNIEnv *cjni_thread_attach (void) /* {{{ */ if (cjni_env == NULL) { /* This pointer is free'd in `cjni_jvm_env_destroy'. */ - cjni_env = (cjni_jvm_env_t *) malloc (sizeof (*cjni_env)); + cjni_env = calloc (1, sizeof (*cjni_env)); if (cjni_env == NULL) { - ERROR ("java plugin: cjni_thread_attach: malloc failed."); + ERROR ("java plugin: cjni_thread_attach: calloc failed."); return (NULL); } - memset (cjni_env, 0, sizeof (*cjni_env)); cjni_env->reference_counter = 0; cjni_env->jvm_env = NULL; @@ -2088,11 +2074,10 @@ static JNIEnv *cjni_thread_attach (void) /* {{{ */ else { int status; - JavaVMAttachArgs args; + JavaVMAttachArgs args = { 0 }; assert (cjni_env->jvm_env == NULL); - memset (&args, 0, sizeof (args)); args.version = JNI_VERSION_1_2; status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, (void *) &args); @@ -2169,7 +2154,7 @@ static int cjni_config_add_jvm_arg (oconfig_item_t *ci) /* {{{ */ return (-1); } - tmp = (char **) realloc (jvm_argv, sizeof (char *) * (jvm_argc + 1)); + tmp = realloc (jvm_argv, sizeof (char *) * (jvm_argc + 1)); if (tmp == NULL) { ERROR ("java plugin: realloc failed."); @@ -2205,7 +2190,7 @@ static int cjni_config_load_plugin (oconfig_item_t *ci) /* {{{ */ if (jvm_env == NULL) return (-1); - class = (java_plugin_class_t *) realloc (java_classes_list, + class = realloc (java_classes_list, (java_classes_list_len + 1) * sizeof (*java_classes_list)); if (class == NULL) { @@ -2801,13 +2786,13 @@ static int cjni_match_target_create (const oconfig_item_t *ci, /* {{{ */ /* Allocate a new callback info structure. This is going to be our user_data * pointer. */ - cbi_ret = (cjni_callback_info_t *) malloc (sizeof (*cbi_ret)); + cbi_ret = calloc (1, sizeof (*cbi_ret)); if (cbi_ret == NULL) { - ERROR ("java plugin: cjni_match_target_create: malloc failed."); + ERROR ("java plugin: cjni_match_target_create: calloc failed."); BAIL_OUT (-1); } - memset (cbi_ret, 0, sizeof (*cbi_ret)); + cbi_ret->object = NULL; cbi_ret->type = type; @@ -2923,9 +2908,8 @@ static int cjni_match_target_invoke (const data_set_t *ds, /* {{{ */ * `value_list_t'. */ if (cbi->type == CB_TYPE_TARGET) { - value_list_t new_vl; + value_list_t new_vl = { 0 }; - memset (&new_vl, 0, sizeof (new_vl)); status = jtoc_value_list (jvm_env, &new_vl, o_vl); if (status != 0) { @@ -3004,7 +2988,7 @@ static int cjni_shutdown_plugins (JNIEnv *jvm_env) /* {{{ */ static int cjni_shutdown (void) /* {{{ */ { JNIEnv *jvm_env; - JavaVMAttachArgs args; + JavaVMAttachArgs args = { 0 }; int status; size_t i; @@ -3012,7 +2996,6 @@ static int cjni_shutdown (void) /* {{{ */ return (0); jvm_env = NULL; - memset (&args, 0, sizeof (args)); args.version = JNI_VERSION_1_2; status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, &args);