From: Sebastian Harl Date: Sat, 16 Aug 2014 17:10:06 +0000 (+0200) Subject: timeseries: Added sdb_timeseries_destroy(). X-Git-Tag: sysdb-0.4.0~31 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b3c5403f90933d3d63ebaf9174524fa018a50f4f;p=sysdb.git timeseries: Added sdb_timeseries_destroy(). --- diff --git a/src/Makefile.am b/src/Makefile.am index c7c53e3..faea551 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,7 +74,7 @@ libsysdb_la_SOURCES = \ core/store_expr.c \ core/store_lookup.c \ core/data.c include/core/data.h \ - include/core/timeseries.h \ + core/timeseries.c include/core/timeseries.h \ frontend/connection.c include/frontend/connection.h \ frontend/connection-private.h \ frontend/parser.c include/frontend/parser.h \ diff --git a/src/core/timeseries.c b/src/core/timeseries.c new file mode 100644 index 0000000..48da7f8 --- /dev/null +++ b/src/core/timeseries.c @@ -0,0 +1,66 @@ +/* + * SysDB - src/core/timeseries.c + * Copyright (C) 2014 Sebastian 'tokkee' Harl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "sysdb.h" +#include "core/timeseries.h" + +#include + +/* + * public API + */ + +void +sdb_timeseries_destroy(sdb_timeseries_t *ts) +{ + size_t i; + + if (! ts) + return; + + if (ts->data) + free(ts->data); + ts->data = NULL; + ts->data_len = 0; + + for (i = 0; i < ts->data_names_len; ++i) { + if (ts->data_names[i]) + free(ts->data_names[i]); + ts->data_names[i] = NULL; + } + if (ts->data_names) + free(ts->data_names); + ts->data_names = NULL; + ts->data_names_len = 0; +} /* sdb_timeseries_destroy */ + +/* vim: set tw=78 sw=4 ts=4 noexpandtab : */ + diff --git a/src/include/core/timeseries.h b/src/include/core/timeseries.h index 3a4029d..52848a7 100644 --- a/src/include/core/timeseries.h +++ b/src/include/core/timeseries.h @@ -69,6 +69,13 @@ typedef struct { sdb_time_t end; } sdb_timeseries_opts_t; +/* + * sdb_timeseries_destroy: + * Destroy a time-series object, freeing all of its memory. + */ +void +sdb_timeseries_destroy(sdb_timeseries_t *ts); + #ifdef __cplusplus } /* extern "C" */ #endif