X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_db_query.c;h=fcded6b414687f10d3773d7a42f58ad8c90581eb;hb=dd09c9364998ad6ef681b70f45f7a9734808cf96;hp=df490e13e505a063885f472426079ceb91584359;hpb=d437681a04278fa6292338b4959231f825652785;p=collectd.git diff --git a/src/utils_db_query.c b/src/utils_db_query.c index df490e13..fcded6b4 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -2,21 +2,26 @@ * collectd - src/utils_db_query.c * Copyright (C) 2008,2009 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" @@ -197,8 +202,9 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ assert (r != NULL); assert (r_area->ds != NULL); assert (((size_t) r_area->ds->ds_num) == r->values_num); + assert (r->values_num > 0); - vl.values = (value_t *) calloc (r_area->ds->ds_num, sizeof (value_t)); + vl.values = (value_t *) calloc (r->values_num, sizeof (value_t)); if (vl.values == NULL) { ERROR ("db query utils: malloc failed."); @@ -240,15 +246,27 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ { if (r->instance_prefix == NULL) { - strjoin (vl.type_instance, sizeof (vl.type_instance), + int status = strjoin (vl.type_instance, sizeof (vl.type_instance), r_area->instances_buffer, r->instances_num, "-"); + if (status < 0) + { + ERROR ("udb_result_submit: creating type_instance failed with status %d.", + status); + return (status); + } } else { char tmp[DATA_MAX_NAME_LEN]; - strjoin (tmp, sizeof (tmp), r_area->instances_buffer, + int status = strjoin (tmp, sizeof (tmp), r_area->instances_buffer, r->instances_num, "-"); + if (status < 0) + { + ERROR ("udb_result_submit: creating type_instance failed with status %d.", + status); + return (status); + } tmp[sizeof (tmp) - 1] = 0; snprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s", @@ -632,7 +650,7 @@ static int udb_result_create (const char *query_name, /* {{{ */ /* * Query private functions */ -void udb_query_free_one (udb_query_t *q) /* {{{ */ +static void udb_query_free_one (udb_query_t *q) /* {{{ */ { if (q == NULL) return; @@ -1066,10 +1084,9 @@ udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */ udb_result_preparation_area_t **next_r_area; udb_result_t *r; - q_area = (udb_query_preparation_area_t *)malloc (sizeof (*q_area)); + q_area = malloc (sizeof (*q_area)); if (q_area == NULL) return NULL; - memset (q_area, 0, sizeof (*q_area)); next_r_area = &q_area->result_prep_areas; @@ -1077,14 +1094,18 @@ udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */ { udb_result_preparation_area_t *r_area; - r_area = (udb_result_preparation_area_t *)malloc (sizeof (*r_area)); + r_area = malloc (sizeof (*r_area)); if (r_area == NULL) { - for (r_area = q_area->result_prep_areas; - r_area != NULL; r_area = r_area->next) + udb_result_preparation_area_t *a = q_area->result_prep_areas; + + while (a != NULL) { - free (r_area); + udb_result_preparation_area_t *next = a->next; + sfree (a); + a = next; } + free (q_area); return NULL; }