X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_mongodb.c;h=8d9ed9df39bc5099c27e21eb02fa4dcbe7ed1e74;hb=13c83b972a8ade7dff6f8f2d00832d446ef6f502;hp=a12bdd01728569dbe33e1d1e2e349a5e633996b1;hpb=0accb683c9a07989c5b945b6217184f13f0b42b5;p=collectd.git diff --git a/src/write_mongodb.c b/src/write_mongodb.c index a12bdd01..8d9ed9df 100644 --- a/src/write_mongodb.c +++ b/src/write_mongodb.c @@ -29,13 +29,12 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" #include "configfile.h" #include "utils_cache.h" -#include - #if HAVE_STDINT_H # define MONGO_HAVE_STDINT 1 #else @@ -43,6 +42,11 @@ #endif #include +#if (MONGO_MAJOR == 0) && (MONGO_MINOR < 8) +# define bson_alloc() bson_create() +# define bson_dealloc(b) bson_dispose(b) +#endif + struct wm_node_s { char name[DATA_MAX_NAME_LEN]; @@ -74,7 +78,7 @@ static bson *wm_create_bson (const data_set_t *ds, /* {{{ */ gauge_t *rates; int i; - ret = bson_create (); + ret = bson_alloc (); /* matched by bson_dealloc() */ if (ret == NULL) { ERROR ("write_mongodb plugin: bson_create failed."); @@ -95,7 +99,7 @@ static bson *wm_create_bson (const data_set_t *ds, /* {{{ */ rates = NULL; } - bson_init (ret); + bson_init (ret); /* matched by bson_destroy() */ bson_append_date (ret, "time", (bson_date_t) CDTIME_T_TO_MS (vl->time)); bson_append_string (ret, "host", vl->host); bson_append_string (ret, "plugin", vl->plugin); @@ -243,7 +247,8 @@ static int wm_write (const data_set_t *ds, /* {{{ */ pthread_mutex_unlock (&node->lock); /* free our resource as not to leak memory */ - bson_destroy (bson_record); + bson_destroy (bson_record); /* matches bson_init() */ + bson_dealloc (bson_record); /* matches bson_alloc() */ return (0); } /* }}} int wm_write */ @@ -268,10 +273,9 @@ static int wm_config_node (oconfig_item_t *ci) /* {{{ */ int status; int i; - node = malloc (sizeof (*node)); + node = calloc (1, sizeof (*node)); if (node == NULL) return (ENOMEM); - memset (node, 0, sizeof (*node)); mongo_init (node->conn); node->host = NULL; node->store_rates = 1;