properly initialize new memory regions after reallocz(); fixes #1972
Costa Tsaousis (ktsaou) committed
Mar 19, 2017 at 00:54 UTC
bb22adc2c47d51c8e0f8ad7c7a95c66e9e53760b
1 file changed
+13
-3
src/freebsd_sysctl.c
+13
-3
@@ -326,8 +326,13 @@ int do_kern_cp_times(int update_every, usec_t dt) {
326
RRDDIM *rd_interrupt;
327
RRDDIM *rd_idle;
328
} *all_cpu_charts = NULL;
329
+ static int old_number_of_cpus = 0;
330
330
- all_cpu_charts = reallocz(all_cpu_charts, sizeof(struct cpu_chart) * number_of_cpus);
331
+ if(unlikely(number_of_cpus > old_number_of_cpus)) {
332
+ all_cpu_charts = reallocz(all_cpu_charts, sizeof(struct cpu_chart) * number_of_cpus);
333
+ memset(&all_cpu_charts[old_number_of_cpus], 0, sizeof(struct softnet_chart) * (number_of_cpus - old_number_of_cpus));
334
+ old_number_of_cpus = number_of_cpus;
335
+ }
336
337
for (i = 0; i < number_of_cpus; i++) {
338
if (unlikely(!all_cpu_charts[i].st)) {
@@ -1277,7 +1282,7 @@ int do_net_isr(int update_every, usec_t dt) {
1282
return 1;
1283
} else {
1284
netisr_stats = reallocz(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1280
- bzero(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1285
+ memset(netisr_stats, 0, (number_of_cpus + 1) * sizeof(struct netisr_stats));
1286
for (i = 0; i < num_netisr_workstreams; i++) {
1287
for (n = 0; n < num_netisr_works; n++) {
1288
if (netisr_workstream[i].snws_wsid == netisr_work[n].snw_wsid) {
@@ -1344,8 +1349,13 @@ int do_net_isr(int update_every, usec_t dt) {
1349
RRDDIM *rd_qdrops;
1350
RRDDIM *rd_queued;
1351
} *all_softnet_charts = NULL;
1352
+ static int old_number_of_cpus = 0;
1353
1348
- all_softnet_charts = reallocz(all_softnet_charts, sizeof(struct softnet_chart) * number_of_cpus);
1354
+ if(unlikely(number_of_cpus > old_number_of_cpus)) {
1355
+ all_softnet_charts = reallocz(all_softnet_charts, sizeof(struct softnet_chart) * number_of_cpus);
1356
+ memset(&all_softnet_charts[old_number_of_cpus], 0, sizeof(struct softnet_chart) * (number_of_cpus - old_number_of_cpus));
1357
+ old_number_of_cpus = number_of_cpus;
1358
+ }
1359
1360
for (i = 0; i < number_of_cpus ;i++) {
1361
snprintfz(all_softnet_charts[i].netisr_cpuid, MAX_INT_DIGITS + 17, "cpu%d_softnet_stat", i);