X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_db_query.c;h=36181ee1423a9832692dd4c190984ee4b013d859;hb=94d84b7b773e9d140b81699d1d42a9e461a5b76d;hp=df490e13e505a063885f472426079ceb91584359;hpb=c7c13abc4c3c72b9baf58dfeec059c9c71e815ea;p=collectd.git diff --git a/src/utils_db_query.c b/src/utils_db_query.c index df490e13..36181ee1 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."); @@ -632,7 +638,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 +1072,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 +1082,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; }