perl: Check for NULL before dereferencing
[collectd.git] / src / rrdtool.c
index bebf468..9b5723a 100644 (file)
@@ -733,7 +733,10 @@ static int rrd_cache_insert (const char *filename,
        {
                rc = malloc (sizeof (*rc));
                if (rc == NULL)
+               {
+                       pthread_mutex_unlock (&cache_lock);
                        return (-1);
+               }
                rc->values_num = 0;
                rc->values = NULL;
                rc->first_value = 0;
@@ -743,6 +746,7 @@ static int rrd_cache_insert (const char *filename,
                new_rc = 1;
        }
 
+       assert (value_time > 0); /* plugin_dispatch() ensures this. */
        if (rc->last_value >= value_time)
        {
                pthread_mutex_unlock (&cache_lock);
@@ -1203,6 +1207,7 @@ static int rrd_init (void)
        cache = c_avl_create ((int (*) (const void *, const void *)) strcmp);
        if (cache == NULL)
        {
+               pthread_mutex_unlock (&cache_lock);
                ERROR ("rrdtool plugin: c_avl_create failed.");
                return (-1);
        }