summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7f9c8e7)
raw | patch | inline | side by side (parent: 7f9c8e7)
author | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Sun, 2 Jul 2017 17:22:20 +0000 (19:22 +0200) | ||
committer | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Sun, 2 Jul 2017 17:23:16 +0000 (19:23 +0200) |
scan-build: Using '/usr/bin/clang-4.0' for static analysis
make all-am
make[1]: Entering directory '/home/ruben/src/collectd'
CC src/write_mongodb_la-write_mongodb.lo
src/write_mongodb.c:173:41: warning: Null pointer passed as an argument to a 'nonnull' parameter
strlen(node->passwd) + strlen(node->host) + 5 +
^~~~~~~~~~~~~~~~~~
src/write_mongodb.c:199:42: warning: Null pointer passed as an argument to a 'nonnull' parameter
uri_length = strlen(format_string) + strlen(node->host) + 5 + 1;
^~~~~~~~~~~~~~~~~~
2 warnings generated.
CCLD write_mongodb.la
make all-am
make[1]: Entering directory '/home/ruben/src/collectd'
CC src/write_mongodb_la-write_mongodb.lo
src/write_mongodb.c:173:41: warning: Null pointer passed as an argument to a 'nonnull' parameter
strlen(node->passwd) + strlen(node->host) + 5 +
^~~~~~~~~~~~~~~~~~
src/write_mongodb.c:199:42: warning: Null pointer passed as an argument to a 'nonnull' parameter
uri_length = strlen(format_string) + strlen(node->host) + 5 + 1;
^~~~~~~~~~~~~~~~~~
2 warnings generated.
CCLD write_mongodb.la
src/write_mongodb.c | patch | blob | history |
diff --git a/src/write_mongodb.c b/src/write_mongodb.c
index 63d3716baf161d303fb5b86f8ea13cde9ddf9526..f585a39660b55582ea18b618f708a78558c48938 100644 (file)
--- a/src/write_mongodb.c
+++ b/src/write_mongodb.c
return 0;
}
- INFO("write_mongodb plugin: Connecting to [%s]:%i",
- (node->host != NULL) ? node->host : "localhost",
- (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT);
+ INFO("write_mongodb plugin: Connecting to [%s]:%d", node->host, node->port);
if ((node->db != NULL) && (node->user != NULL) && (node->passwd != NULL)) {
format_string = "mongodb://%s:%s@%s:%d/?authSource=%s";
node->client = mongoc_client_new(uri);
if (!node->client) {
- ERROR("write_mongodb plugin: Authenticating to [%s]%i for database "
+ ERROR("write_mongodb plugin: Authenticating to [%s]:%d for database "
"\"%s\" as user \"%s\" failed.",
- (node->host != NULL) ? node->host : "localhost",
- (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT, node->db,
- node->user);
+ node->host, node->port, node->db, node->user);
node->connected = 0;
sfree(uri);
return -1;
node->client = mongoc_client_new(uri);
if (!node->client) {
- ERROR("write_mongodb plugin: Connecting to [%s]:%i failed.",
- (node->host != NULL) ? node->host : "localhost",
- (node->port != 0) ? node->port : MONGOC_DEFAULT_PORT);
+ ERROR("write_mongodb plugin: Connecting to [%s]:%d failed.", node->host,
+ node->port);
node->connected = 0;
sfree(uri);
return -1;
if (node == NULL)
return ENOMEM;
mongoc_init();
- node->host = NULL;
+ node->host = strdup("localhost");
+ if (node->host == NULL) {
+ sfree(node);
+ return ENOMEM;
+ }
+ node->port = MONGOC_DEFAULT_PORT;
node->store_rates = 1;
pthread_mutex_init(&node->lock, /* attr = */ NULL);
status = cf_util_get_string_buffer(ci, node->name, sizeof(node->name));
if (status != 0) {
+ sfree(node->host);
sfree(node);
return status;
}