@cryptotaxi247 / netdata-1 / commits / a005538f3

fixed a bug in config_get() where it was constantly overwriting values with the default

Costa Tsaousis (ktsaou) committed Mar 26, 2015 at 00:13 UTC a005538f326ab85d5a17d0dd4d1dc939ab2542c5
1 file changed +7 -6
src/config.c
+7 -6
@@ -256,7 +256,10 @@ char *config_get(const char *section, const char *name, const char *default_valu
256 if(!co) co = config_create(section);
257
258 cv = config_value_index_find(co, name, 0);
259 - if(!cv) cv = config_value_create(co, name, default_value);
259 + if(!cv) {
260 + cv = config_value_create(co, name, default_value);
261 + if(!cv) return NULL;
262 + }
263 cv->flags |= CONFIG_VALUE_USED;
264
265 if(cv->flags & CONFIG_VALUE_LOADED || cv->flags & CONFIG_VALUE_CHANGED) {
@@ -267,11 +270,6 @@ char *config_get(const char *section, const char *name, const char *default_valu
270 cv->flags |= CONFIG_VALUE_CHECKED;
271 }
272 }
270 - else {
271 - // this is not loaded from the config
272 - // copy the default value to it
273 - strncpy(cv->value, default_value, CONFIG_MAX_VALUE);
274 - }
273
274 pthread_rwlock_unlock(&config_rwlock);
275 return(cv->value);
@@ -283,6 +281,8 @@ long long config_get_number(const char *section, const char *name, long long val
281 sprintf(buffer, "%lld", value);
282
283 s = config_get(section, name, buffer);
284 + if(!s) return 0;
285 +
286 return strtoll(s, NULL, 0);
287 }
288
@@ -293,6 +293,7 @@ int config_get_boolean(const char *section, const char *name, int value)
293 else s = "no";
294
295 s = config_get(section, name, s);
296 + if(!s) return 0;
297
298 if(strcmp(s, "yes") == 0 || strcmp(s, "true") == 0 || strcmp(s, "1") == 0) {
299 strcpy(s, "yes");