/**
* collectd - src/write_mongodb.c
- * Copyright (C) 2010 Florian Forster, Akkarit Sangpetch
+ * Copyright (C) 2010 Florian Forster
+ * Copyright (C) 2010 Akkarit Sangpetch
+ * Copyright (C) 2012 Chris Lundquist
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*
* Authors:
* Florian Forster <ff at octo.it>
- * Akkarit Sangpetch <asangpet@andrew.cmu.edu>
+ * Akkarit Sangpetch <asangpet at andrew.cmu.edu>
+ * Chris Lundquist <clundquist at bluebox.net>
**/
#include "collectd.h"
else
assert (23 == 42);
}
+ /* We must finish the record, other wise the insert will fail */
bson_finish(&record);
pthread_mutex_lock (&node->lock);
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 */