@cryptotaxi247 / netdata-1 / commits / 93d93d3d9

allocate histogram extensions before indexing the metric, to prevent crash in multi-threaded operation

Costa Tsaousis (ktsaou) committed Apr 27, 2017 at 01:36 UTC 93d93d3d9cb697fd600e995490293988d05bb951
1 file changed +6 -6
src/statsd.c
+6 -6
@@ -251,8 +251,14 @@ static inline STATSD_METRIC *statsd_find_or_add_metric(STATSD_INDEX *index, char
251 m->name = strdupz(metric);
252 m->hash = hash;
253 m->options = index->default_options;
254 +
255 + if(index == &statsd.histograms || index == &statsd.timers) {
256 + m->histogram.ext = callocz(sizeof(STATSD_METRIC_HISTOGRAM_EXTENSIONS), 1);
257 + netdata_mutex_init(&m->histogram.mutex);
258 + }
259 STATSD_METRIC *n = (STATSD_METRIC *)STATSD_AVL_INSERT(&index->index, (avl *)m);
260 if(unlikely(n != m)) {
261 + freez((void *)m->histogram.ext);
262 freez((void *)m->name);
263 freez((void *)m);
264 m = n;
@@ -262,12 +268,6 @@ static inline STATSD_METRIC *statsd_find_or_add_metric(STATSD_INDEX *index, char
268 index->metrics++;
269 m->next = index->first;
270 index->first = m;
265 -
266 - if(index == &statsd.histograms || index == &statsd.timers) {
267 - m->histogram.ext = callocz(sizeof(STATSD_METRIC_HISTOGRAM_EXTENSIONS), 1);
268 - netdata_mutex_init(&m->histogram.mutex);
269 - }
270 -
271 STATSD_FIRST_PTR_MUTEX_UNLOCK(index);
272 }
273 }