Fix SEGV by removing free of vars of charts that do not exist (#5455)
Chris Akritidis committed
Feb 21, 2019 at 11:28 UTC
b8821bbde9ed330a59b9c145747e2fa628f1570b
1 file changed
+13
-23
collectors/cgroups.plugin/sys_fs_cgroup.c
+13
-23
@@ -901,14 +901,15 @@ static inline void cgroup_get_chart_name(struct cgroup *cg) {
901
if(s && *s && *s != '\n') {
902
debug(D_CGROUP, "cgroup '%s' should be renamed to '%s'", cg->id, s);
903
904
- trim(s);
905
-
906
- freez(cg->chart_title);
907
- cg->chart_title = cgroup_title_strdupz(s);
908
-
909
- freez(cg->chart_id);
910
- cg->chart_id = cgroup_chart_id_strdupz(s);
911
- cg->hash_chart = simple_hash(cg->chart_id);
904
+ s = trim(s);
905
+ if (s) {
906
+ freez(cg->chart_title);
907
+ cg->chart_title = cgroup_title_strdupz(s);
908
+
909
+ freez(cg->chart_id);
910
+ cg->chart_id = cgroup_chart_id_strdupz(s);
911
+ cg->hash_chart = simple_hash(cg->chart_id);
912
+ }
913
}
914
}
915
else
@@ -1041,26 +1042,15 @@ static inline struct cgroup *cgroup_add(const char *id) {
1042
static inline void cgroup_free(struct cgroup *cg) {
1043
debug(D_CGROUP, "Removing cgroup '%s' with chart id '%s' (was %s and %s)", cg->id, cg->chart_id, (cg->enabled)?"enabled":"disabled", (cg->available)?"available":"not available");
1044
1044
- if(cg->st_cpu) {
1045
- rrdset_wrlock(cg->st_cpu);
1046
- rrdsetvar_free(cg->chart_var_cpu_limit);
1047
- rrdset_unlock(cg->st_cpu);
1048
- rrdset_is_obsolete(cg->st_cpu);
1049
- rrdset_is_obsolete(cg->st_cpu_limit);
1050
- }
1045
+ if(cg->st_cpu) rrdset_is_obsolete(cg->st_cpu);
1046
+ if(cg->st_cpu_limit) rrdset_is_obsolete(cg->st_cpu_limit);
1047
if(cg->st_cpu_per_core) rrdset_is_obsolete(cg->st_cpu_per_core);
1048
if(cg->st_mem) rrdset_is_obsolete(cg->st_mem);
1049
if(cg->st_writeback) rrdset_is_obsolete(cg->st_writeback);
1050
if(cg->st_mem_activity) rrdset_is_obsolete(cg->st_mem_activity);
1051
if(cg->st_pgfaults) rrdset_is_obsolete(cg->st_pgfaults);
1056
- if(cg->st_mem_usage) {
1057
- rrdset_wrlock(cg->st_mem_usage);
1058
- rrdsetvar_free(cg->chart_var_memory_limit);
1059
- rrdsetvar_free(cg->chart_var_memoryswap_limit);
1060
- rrdset_unlock(cg->st_mem_usage);
1061
- rrdset_is_obsolete(cg->st_mem_usage);
1062
- rrdset_is_obsolete(cg->st_mem_usage_limit);
1063
- }
1052
+ if(cg->st_mem_usage) rrdset_is_obsolete(cg->st_mem_usage);
1053
+ if (cg->st_mem_usage_limit) rrdset_is_obsolete(cg->st_mem_usage_limit);
1054
if(cg->st_mem_failcnt) rrdset_is_obsolete(cg->st_mem_failcnt);
1055
if(cg->st_io) rrdset_is_obsolete(cg->st_io);
1056
if(cg->st_serviced_ops) rrdset_is_obsolete(cg->st_serviced_ops);