Increment the DataSetsWritten counter before freeing the RRD values. --kevin
[rrdtool.git] / src / rrd_daemon.c
index 36701f8..0e95e90 100644 (file)
@@ -820,14 +820,15 @@ static void *flush_thread_main (void *args __attribute__((unused))) /* {{{ */
         || ((now.tv_sec == next_flush.tv_sec)
           && ((1000 * now.tv_usec) > next_flush.tv_nsec)))
     {
+      RRDD_LOG(LOG_DEBUG, "flushing old values");
+
+      /* Determine the time of the next cache flush. */
+      next_flush.tv_sec = now.tv_sec + config_flush_interval;
+
       /* Flush all values that haven't been written in the last
        * `config_write_interval' seconds. */
       flush_old_values (config_write_interval);
 
-      /* Determine the time of the next cache flush. */
-      next_flush.tv_sec =
-        now.tv_sec + next_flush.tv_sec % config_flush_interval;
-
       /* unlock the cache while we rotate so we don't block incoming
        * updates if the fsync() blocks on disk I/O */
       pthread_mutex_unlock(&cache_lock);
@@ -923,9 +924,6 @@ static void *queue_thread_main (void *args __attribute__((unused))) /* {{{ */
       pthread_cond_broadcast(&ci->flushed);
     pthread_mutex_unlock(&cache_lock);
 
-    rrd_free_ptrs((void ***) &values, &values_num);
-    free(file);
-
     if (status == 0)
     {
       pthread_mutex_lock (&stats_lock);
@@ -934,6 +932,9 @@ static void *queue_thread_main (void *args __attribute__((unused))) /* {{{ */
       pthread_mutex_unlock (&stats_lock);
     }
 
+    rrd_free_ptrs((void ***) &values, &values_num);
+    free(file);
+
     pthread_mutex_lock (&cache_lock);
   }
   pthread_mutex_unlock (&cache_lock);