@cryptotaxi247 / netdata-1 / commits / 39db23366

fixed a memory leak in badges; allow dimensions with space to be found; allow dimensions to be found by id too

Costa Tsaousis (ktsaou) committed Jun 6, 2016 at 23:23 UTC 39db23366059d0daf6a14422d37eea26ebf8af58
3 files changed +12 -5
src/rrd.h
+3
@@ -114,6 +114,9 @@ struct rrddim {
114 // instead of strcmp() every item in the binary index
115 // we first compare the hashes
116
117 + // FIXME
118 + // we need the hash_name too!
119 +
120 uint32_t flags;
121
122 char cache_filename[FILENAME_MAX+1]; // the filename we load/save from/to this set
src/rrd2json.c
+4 -2
@@ -374,12 +374,14 @@ void rrdr_disable_not_selected_dimensions(RRDR *r, const char *dims)
374 for(c = 0, d = r->st->dimensions; d ;c++, d = d->next)
375 r->od[c] |= RRDR_HIDDEN;
376
377 - while(o && *o && (tok = mystrsep(&o, ", |"))) {
377 + while(o && *o && (tok = mystrsep(&o, ",|"))) {
378 if(!*tok) continue;
379 +
380 + uint32_t hash = simple_hash(tok);
381
382 // find it and enable it
383 for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
382 - if(!strcmp(d->name, tok)) {
384 + if(unlikely((hash == d->hash && !strcmp(d->id, tok)) || !strcmp(d->name, tok))) {
385 r->od[c] &= ~RRDR_HIDDEN;
386
387 // since the user needs this dimension
src/web_client.c
+5 -3
@@ -737,7 +737,9 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
737
738 if(!strcmp(name, "chart")) chart = value;
739 else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) {
740 - if(!dimensions) dimensions = buffer_create(strlen(value));
740 + if(!dimensions)
741 + dimensions = buffer_create(strlen(value));
742 +
743 if(dimensions) {
744 buffer_strcat(dimensions, "|");
745 buffer_strcat(dimensions, value);
@@ -845,10 +847,10 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
847
848 // render the badge
849 buffer_svg(w->response.data, label, n * multiply / divide, units, label_color, value_color, value_is_null, precision);
848 - return ret;
850
851 cleanup:
851 - if(dimensions) buffer_free(dimensions);
852 + if(dimensions)
853 + buffer_free(dimensions);
854 return ret;
855 }
856