diff --git a/daemon/analytics.c b/daemon/analytics.c index be1e1caa658bf2..de09a696008bf2 100644 --- a/daemon/analytics.c +++ b/daemon/analytics.c @@ -116,12 +116,14 @@ void analytics_free_data(void) */ void analytics_set_data(char **name, char *value) { + spinlock_lock(&analytics_data.spinlock); if (*name) { analytics_data.data_length -= strlen(*name); freez(*name); } *name = strdupz(value); analytics_data.data_length += strlen(*name); + spinlock_unlock(&analytics_data.spinlock); } /* @@ -130,6 +132,7 @@ void analytics_set_data(char **name, char *value) void analytics_set_data_str(char **name, const char *value) { size_t value_string_len; + spinlock_lock(&analytics_data.spinlock); if (*name) { analytics_data.data_length -= strlen(*name); freez(*name); @@ -138,6 +141,7 @@ void analytics_set_data_str(char **name, const char *value) *name = mallocz(sizeof(char) * value_string_len); snprintfz(*name, value_string_len - 1, "\"%s\"", value); analytics_data.data_length += strlen(*name); + spinlock_unlock(&analytics_data.spinlock); } /* @@ -466,6 +470,8 @@ void analytics_alarms(void) */ void analytics_misc(void) { + analytics_data.spinlock.locked = false; + #ifdef ENABLE_ACLK analytics_set_data(&analytics_data.netdata_host_cloud_available, "true"); analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "Next Generation"); diff --git a/daemon/analytics.h b/daemon/analytics.h index 4ba625683efd64..04991036ce82d3 100644 --- a/daemon/analytics.h +++ b/daemon/analytics.h @@ -71,6 +71,7 @@ struct analytics_data { size_t charts_count; size_t metrics_count; + SPINLOCK spinlock; bool exporting_enabled; };