diff --git a/include/villas/hist.h b/include/villas/hist.h index fefd3a728..289affa78 100644 --- a/include/villas/hist.h +++ b/include/villas/hist.h @@ -44,7 +44,7 @@ struct hist { void hist_create(struct hist *h, double start, double end, double resolution); /** Free the dynamically allocated memory. */ -void hist_destroy(struct hist *h); +int hist_destroy(struct hist *h); /** Reset all counters and values back to zero. */ void hist_reset(struct hist *h); diff --git a/include/villas/list.h b/include/villas/list.h index 2e3e5ec6c..26d10fbaf 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -40,7 +40,7 @@ * * @param data A pointer to the data which should be freed. */ -typedef void (*dtor_cb_t)(void *); +typedef int (*dtor_cb_t)(void *); /** Callback to search or sort a list. */ typedef int (*cmp_cb_t)(const void *, const void *); @@ -65,7 +65,7 @@ void list_init(struct list *l); * @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed. * @param l A pointer to the list data structure. */ -void list_destroy(struct list *l, dtor_cb_t dtor, bool free); +int list_destroy(struct list *l, dtor_cb_t dtor, bool free); /** Append an element to the end of the list */ void list_push(struct list *l, void *p); diff --git a/include/villas/node.h b/include/villas/node.h index af24a35cb..19111cec4 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -198,7 +198,7 @@ struct node * node_create(struct node_type *vt); * * @see node_type::destroy */ -void node_destroy(struct node *n); +int node_destroy(struct node *n); /** Start operation of a node. * diff --git a/include/villas/path.h b/include/villas/path.h index e09109a3e..6aec9ed5c 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -85,7 +85,7 @@ void path_init(struct path *p); * * @param i A pointer to the path structure. */ -void path_destroy(struct path *p); +int path_destroy(struct path *p); /** Initialize pool queue and hooks. * diff --git a/lib/hist.c b/lib/hist.c index 8f29f6597..89da433e5 100644 --- a/lib/hist.c +++ b/lib/hist.c @@ -30,9 +30,11 @@ void hist_create(struct hist *h, double low, double high, double resolution) hist_reset(h); } -void hist_destroy(struct hist *h) +int hist_destroy(struct hist *h) { free(h->data); + + return 0; } void hist_put(struct hist *h, double value) diff --git a/lib/list.c b/lib/list.c index aa87553de..77f6f3fd5 100644 --- a/lib/list.c +++ b/lib/list.c @@ -42,7 +42,7 @@ void list_init(struct list *l) l->array = NULL; } -void list_destroy(struct list *l, dtor_cb_t destructor, bool release) +int list_destroy(struct list *l, dtor_cb_t destructor, bool release) { pthread_mutex_lock(&l->lock); @@ -62,6 +62,8 @@ void list_destroy(struct list *l, dtor_cb_t destructor, bool release) pthread_mutex_unlock(&l->lock); pthread_mutex_destroy(&l->lock); + + return 0; } void list_push(struct list *l, void *p) diff --git a/lib/node.c b/lib/node.c index b4aa9dc02..9a4284e04 100644 --- a/lib/node.c +++ b/lib/node.c @@ -193,7 +193,7 @@ struct node * node_create(struct node_type *vt) return n; } -void node_destroy(struct node *n) +int node_destroy(struct node *n) { if (n->_vt->destroy) n->_vt->destroy(n); @@ -203,4 +203,6 @@ void node_destroy(struct node *n) free(n->_vd); free(n->_name); free(n); + + return 0; } diff --git a/lib/nodes/ngsi.c b/lib/nodes/ngsi.c index e50b1c25c..d675eb056 100644 --- a/lib/nodes/ngsi.c +++ b/lib/nodes/ngsi.c @@ -429,26 +429,30 @@ char * ngsi_print(struct node *n) i->endpoint, i->timeout, list_length(&i->mapping)); } -static void ngsi_destroy_metadata(struct ngsi_metadata *meta) +static int ngsi_metadata_destroy(struct ngsi_metadata *meta) { free(meta->value); free(meta->name); free(meta->type); + + return 0; } -static void ngsi_destroy_attribute(struct ngsi_attribute *attr) +static int ngsi_attribute_destroy(struct ngsi_attribute *attr) { free(attr->name); free(attr->type); - list_destroy(&attr->metadata, (dtor_cb_t) ngsi_destroy_metadata, true); + list_destroy(&attr->metadata, (dtor_cb_t) ngsi_metadata_destroy, true); + + return 0; } int ngsi_destroy(struct node *n) { struct ngsi *i = n->_vd; - list_destroy(&i->mapping, (dtor_cb_t) ngsi_destroy_attribute, true); + list_destroy(&i->mapping, (dtor_cb_t) ngsi_attribute_destroy, true); return 0; } diff --git a/lib/path.c b/lib/path.c index a1693f2b1..d860ceac1 100644 --- a/lib/path.c +++ b/lib/path.c @@ -197,6 +197,21 @@ void path_init(struct path *p) p->state = PATH_CREATED; } +int path_destroy(struct path *p) +{ + hook_run(p, NULL, 0, HOOK_DEINIT); /* Release memory */ + + list_destroy(&p->destinations, NULL, false); + list_destroy(&p->hooks, NULL, true); + + queue_destroy(&p->queue); + pool_destroy(&p->pool); + + free(p->_name); + + return 0; +} + int path_prepare(struct path *p) { int ret; @@ -226,19 +241,6 @@ int path_prepare(struct path *p) return 0; } -void path_destroy(struct path *p) -{ - hook_run(p, NULL, 0, HOOK_DEINIT); /* Release memory */ - - list_destroy(&p->destinations, NULL, false); - list_destroy(&p->hooks, NULL, true); - - queue_destroy(&p->queue); - pool_destroy(&p->pool); - - free(p->_name); -} - int path_uses_node(struct path *p, struct node *n) { return (p->in == n) || list_contains(&p->destinations, n) ? 0 : 1; } diff --git a/lib/pool.c b/lib/pool.c index d84f24c81..9d3c7f0b6 100644 --- a/lib/pool.c +++ b/lib/pool.c @@ -43,4 +43,6 @@ int pool_destroy(struct pool *p) queue_destroy(&p->queue); return memory_free(p->mem, p->buffer, p->len); + + return 0; } \ No newline at end of file