Reduce allocation size of cp_time_n and cp_time_o on FreeBSD and DragonFlyBSD - #873
Conversation
|
A similar change might be necessary for other BSD variants too. Can you have a look and include the necessary changes too? |
| fpl->cp_time_o = xCalloc(1, sizeof_cp_time_array); | ||
| fpl->cp_time_n = xCalloc(1, sizeof_cp_time_array); |
There was a problem hiding this comment.
Given this allocates an array of unsigned long this should better be:
| fpl->cp_time_o = xCalloc(1, sizeof_cp_time_array); | |
| fpl->cp_time_n = xCalloc(1, sizeof_cp_time_array); | |
| fpl->cp_time_o = xCalloc(CPU_STATES, sizeof(unsigned long)); | |
| fpl->cp_time_n = xCalloc(CPU_STATES, sizeof(unsigned long)); |
There was a problem hiding this comment.
I thought about it but find it better to re-use the same variable instead to make more obvious that we're allocating it for only one "CPU state". If you really prefer me to update it though, I'll (please confirm whether or not you want me to update it).
There was a problem hiding this comment.
There is a somewhat subtle issue here: calloc does not only an overflow check that the current version is missing, but also ensures proper alignment. Depending on the exact values used here, this may make a difference, causing the actual allocation being larger due to proper alignment of allocated elements (See note here).
There was a problem hiding this comment.
CPU_STATES -> CPUSTATES in the suggested change
94e5bba to
b595f57
Compare
|
I looked into all |
b595f57 to
ae35787
Compare
Unless I'm missing something, these two arrays are only ever used to read one set of CPU data, not X (where X is the number of CPUs).
Usage is here and allocation is here.