]> arthur.barton.de Git - netdata.git/commitdiff
error handling in key areas #102
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 31 Mar 2016 17:30:10 +0000 (20:30 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 31 Mar 2016 17:30:10 +0000 (20:30 +0300)
src/avl.c
src/main.c
src/plugin_tc.c
src/url.c

index 4eb0ce0e4b272b3df6e7f8e7ca8587687805a98b..e1684d254fd73cbaa010b4e07ec5046c592e2902 100755 (executable)
--- a/src/avl.c
+++ b/src/avl.c
@@ -17,6 +17,7 @@
 #include <config.h>
 #endif
 #include "avl.h"
+#include "log.h"
 
 /* Private methods */
 int _avl_removeroot(avl_tree* t);
@@ -390,9 +391,14 @@ int avl_search(avl_tree* t, avl* a, int (*iter)(avl* a), avl** ret) {
 void avl_init(avl_tree* t, int (*compar)(void* a, void* b)) {
        t->root = NULL;
        t->compar = compar;
+
+       int lock;
 #ifdef AVL_LOCK_WITH_MUTEX
-       pthread_mutex_init(&t->mutex, NULL);
+       lock = pthread_mutex_init(&t->mutex, NULL);
 #else
-       pthread_rwlock_init(&t->rwlock, NULL);
+       lock = pthread_rwlock_init(&t->rwlock, NULL);
 #endif
+
+       if(lock != 0)
+               fatal("Failed to initialize AVL mutex/rwlock, error: %d", lock);
 }
index aaddc9d06f74e183c681675534d65eae636d2abc..12b4148b7c90062ad484b874e20538074e0a523f 100755 (executable)
@@ -460,6 +460,8 @@ int main(int argc, char **argv)
 
                if(st->enabled) {
                        st->thread = malloc(sizeof(pthread_t));
+                       if(!st->thread)
+                               fatal("Cannot allocate pthread_t memory");
 
                        info("Starting thread %s.", st->name);
 
index f02b707885caed67367870648425d760d4f901f4..4a5d3e4f8ba55e0d180fe528963f68f7b7fef333 100755 (executable)
@@ -346,11 +346,15 @@ static struct tc_device *tc_device_create(char *id)
 
                d->classes_index.root = NULL;
                d->classes_index.compar = tc_class_compare;
+
+               int lock;
 #ifdef AVL_LOCK_WITH_MUTEX
-               pthread_mutex_init(&d->classes_index.mutex, NULL);
+               lock = pthread_mutex_init(&d->classes_index.mutex, NULL);
 #else
-               pthread_rwlock_init(&d->classes_index.rwlock, NULL);
+               lock = pthread_rwlock_init(&d->classes_index.rwlock, NULL);
 #endif
+               if(lock != 0)
+                       fatal("Failed to initialize plugin_tc mutex/rwlock, return code %d.", lock);
 
                tc_device_index_add(d);
 
index c4933b2051579156a2edbac694eb7bb19ec04c50..edf52be7c7c2306c19116e58c54c61524dc90e74 100755 (executable)
--- a/src/url.c
+++ b/src/url.c
@@ -31,6 +31,9 @@ char *url_encode(char *str) {
                *buf = malloc(strlen(str) * 3 + 1),
                *pbuf = buf;
 
+       if(!buf)
+               fatal("Cannot allocate memory.");
+
        while (*pstr) {
                if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
                        *pbuf++ = *pstr;
@@ -56,7 +59,8 @@ char *url_decode(char *str) {
                *buf = malloc(strlen(str) + 1),
                *pbuf = buf;
 
-       if(!buf) fatal("Cannot allocate memory.");
+       if(!buf)
+               fatal("Cannot allocate memory.");
 
        while (*pstr) {
                if (*pstr == '%') {