X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdbi.c;h=6e98168788526a4b9a515d14ecf84969c0c34590;hb=f81aafecc0b537b4bec734f7fdb0c8352719afee;hp=94d0762d261fada2a4ebda04278f43947dc0b006;hpb=a1e7183991a922b4eeca02aafaf45cd675688570;p=collectd.git diff --git a/src/dbi.c b/src/dbi.c index 94d0762d..6e981687 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -148,7 +148,7 @@ static int cdbi_result_get_field (dbi_result res, /* {{{ */ else if (src_type == DBI_TYPE_STRING) { const char *value; - + value = dbi_result_get_string_idx (res, index); if (value == NULL) sstrncpy (buffer, "", buffer_size); @@ -214,7 +214,7 @@ static void cdbi_database_free (cdbi_database_t *db) /* {{{ */ * * ... * - * + * * * Driver "mysql" * Interval 120 @@ -294,13 +294,12 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = (cdbi_database_t *) malloc (sizeof (*db)); + db = calloc (1, sizeof (*db)); if (db == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); return (-1); } - memset (db, 0, sizeof (*db)); status = cf_util_get_string (ci, &db->name); if (status != 0) @@ -357,12 +356,11 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ while ((status == 0) && (db->queries_num > 0)) { size_t j; - db->q_prep_areas = (udb_query_preparation_area_t **) calloc ( - db->queries_num, sizeof (*db->q_prep_areas)); + db->q_prep_areas = calloc (db->queries_num, sizeof (*db->q_prep_areas)); if (db->q_prep_areas == NULL) { - WARNING ("dbi plugin: malloc failed"); + WARNING ("dbi plugin: calloc failed"); status = -1; break; } @@ -512,7 +510,6 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ column_names = NULL; column_values = NULL; - res = NULL; statement = udb_query_get_statement (q); assert (statement != NULL); @@ -548,35 +545,33 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ } /* Allocate `column_names' and `column_values'. {{{ */ - column_names = (char **) calloc (column_num, sizeof (char *)); + column_names = calloc (column_num, sizeof (*column_names)); if (column_names == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } - column_names[0] = (char *) calloc (column_num, - DATA_MAX_NAME_LEN * sizeof (char)); + column_names[0] = calloc (column_num, DATA_MAX_NAME_LEN); if (column_names[0] == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } for (i = 1; i < column_num; i++) column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN; - column_values = (char **) calloc (column_num, sizeof (char *)); + column_values = calloc (column_num, sizeof (*column_values)); if (column_values == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } - column_values[0] = (char *) calloc (column_num, - DATA_MAX_NAME_LEN * sizeof (char)); + column_values[0] = calloc (column_num, DATA_MAX_NAME_LEN); if (column_values[0] == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } for (i = 1; i < column_num; i++)