X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fstore.c;h=a1cf8f6bc44b6ba816fc66ee729189c4371da07d;hp=345b5ea86bf2555c42961b4778ccb800743066b7;hb=2a0b199b7aac87fee49ebefe69d6f94a9045f4b8;hpb=2faa3926a2836c0fe560bc73c7a8df4b9993b3be diff --git a/src/core/store.c b/src/core/store.c index 345b5ea..a1cf8f6 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -818,6 +818,8 @@ sdb_store_fetch_timeseries(const char *hostname, const char *metric, sdb_timeseries_t *ts; + int status = 0; + if ((! hostname) || (! metric) || (! opts) || (! buf)) return -1; @@ -844,6 +846,7 @@ sdb_store_fetch_timeseries(const char *hostname, const char *metric, sdb_log(SDB_LOG_ERR, "store: Failed to fetch time-series '%s/%s' " "- no data-store configured for the stored metric", hostname, metric); + sdb_object_deref(SDB_OBJ(m)); pthread_rwlock_unlock(&host_lock); return -1; } @@ -861,13 +864,14 @@ sdb_store_fetch_timeseries(const char *hostname, const char *metric, sdb_log(SDB_LOG_ERR, "store: Failed to fetch time-series '%s/%s' " "- %s fetcher callback returned no data for '%s'", hostname, metric, type, id); - return -1; + status = -1; } } ts_tojson(ts, buf); + sdb_object_deref(SDB_OBJ(m)); sdb_timeseries_destroy(ts); - return 0; + return status; } /* sdb_store_fetch_timeseries */ int @@ -898,12 +902,18 @@ sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res) tmp.data.datetime = obj->interval; break; case SDB_FIELD_BACKEND: - { + if (! res) + return 0; tmp.type = SDB_TYPE_ARRAY | SDB_TYPE_STRING; tmp.data.array.length = obj->backends_num; tmp.data.array.values = obj->backends; return sdb_data_copy(res, &tmp); - } + case SDB_FIELD_VALUE: + if (obj->type != SDB_ATTRIBUTE) + return -1; + if (! res) + return 0; + return sdb_data_copy(res, &ATTR(obj)->value); default: return -1; }