@cryptotaxi247 / netdata-1 / commits / c53f7665e

support for huge amount of mountpoints - avoid stack overflow due to recursion; fixes #3254

Costa Tsaousis (ktsaou) committed Jan 10, 2018 at 17:34 UTC c53f7665e94c7a1f01daf8211d90ec236118879c
5 files changed +17 -16
src/plugin_proc_diskspace.c
+2 -2
@@ -13,8 +13,8 @@ static inline void mountinfo_reload(int force) {
13 time_t now = now_realtime_sec();
14
15 if(force || now - last_loaded >= check_for_new_mountpoints_every) {
16 - // mountinfo_free() can be called with NULL disk_mountinfo_root
17 - mountinfo_free(disk_mountinfo_root);
16 + // mountinfo_free_all() can be called with NULL disk_mountinfo_root
17 + mountinfo_free_all(disk_mountinfo_root);
18
19 // re-read mountinfo in case something changed
20 disk_mountinfo_root = mountinfo_read(0);
src/proc_diskstats.c
+2 -2
@@ -249,8 +249,8 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
249 // mountinfo_find() can be called with NULL disk_mountinfo_root
250 struct mountinfo *mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
251 if(unlikely(!mi)) {
252 - // mountinfo_free can be called with NULL
253 - mountinfo_free(disk_mountinfo_root);
252 + // mountinfo_free_all can be called with NULL
253 + mountinfo_free_all(disk_mountinfo_root);
254 disk_mountinfo_root = mountinfo_read(0);
255 mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
256 }
src/proc_self_mountinfo.c
+11 -10
@@ -103,20 +103,11 @@ struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *ro
103 return NULL;
104 }
105
106 -
107 -// free a linked list of mountinfo structures
108 -void mountinfo_free(struct mountinfo *mi) {
109 - if(unlikely(!mi))
110 - return;
111 -
112 - if(likely(mi->next))
113 - mountinfo_free(mi->next);
114 -
106 +static void mountinfo_free(struct mountinfo *mi) {
107 freez(mi->root);
108 freez(mi->mount_point);
109 freez(mi->mount_options);
110 freez(mi->persistent_id);
119 -
111 /*
112 if(mi->optional_fields_count) {
113 int i;
@@ -131,6 +122,16 @@ void mountinfo_free(struct mountinfo *mi) {
122 freez(mi);
123 }
124
125 +// free a linked list of mountinfo structures
126 +void mountinfo_free_all(struct mountinfo *mi) {
127 + while(mi) {
128 + struct mountinfo *t = mi;
129 + mi = mi->next;
130 +
131 + mountinfo_free(t);
132 + }
133 +}
134 +
135 static char *strdupz_decoding_octal(const char *string) {
136 char *buffer = strdupz(string);
137
src/proc_self_mountinfo.h
+1 -1
@@ -49,7 +49,7 @@ extern struct mountinfo *mountinfo_find(struct mountinfo *root, unsigned long ma
49 extern struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *root, const char *filesystem, const char *mount_source);
50 extern struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *root, const char *filesystem, const char *super_options);
51
52 -extern void mountinfo_free(struct mountinfo *mi);
52 +extern void mountinfo_free_all(struct mountinfo *mi);
53 extern struct mountinfo *mountinfo_read(int do_statvfs);
54
55 #endif /* NETDATA_PROC_SELF_MOUNTINFO_H */
\ No newline at end of file
src/sys_fs_cgroup.c
+1 -1
@@ -225,7 +225,7 @@ void read_cgroup_plugin_configuration() {
225 ), NULL, SIMPLE_PATTERN_EXACT);
226 }
227
228 - mountinfo_free(root);
228 + mountinfo_free_all(root);
229 }
230
231 // ----------------------------------------------------------------------------