Changes in irq plugin:
[collectd.git] / src / write_mongodb.c
index 510caf9..4deb24d 100644 (file)
@@ -92,6 +92,7 @@ static int wm_write (const data_set_t *ds, /* {{{ */
     else
       assert (23 == 42);
   }
+  /* We must finish the record, other wise the insert will fail */
   bson_finish(&record);
 
   pthread_mutex_lock (&node->lock);
@@ -122,18 +123,15 @@ static int wm_write (const data_set_t *ds, /* {{{ */
   if(status != MONGO_OK)
   {
     ERROR ( "write_mongodb plugin: error inserting record: %d", node->conn->err);
-    if(node->conn->err == MONGO_BSON_INVALID)
-    {
-      ERROR (node->conn->errstr);
-    } else if ( record.err)
-    {
-      ERROR (record.errstr);
-    }
-
+    if (node->conn->err == MONGO_BSON_INVALID)
+      ERROR ("write_mongodb plugin: %s", node->conn->errstr);
+    else if (record.err)
+      ERROR ("write_mongodb plugin: %s", record.errstr);
   }
 
-
   pthread_mutex_unlock (&node->lock);
+  /* free our resource as not to leak memory */
+  bson_destroy(&record);
 
   return (0);
 } /* }}} int wm_write */