-
-
Notifications
You must be signed in to change notification settings - Fork 487
Reduce allocation size of cp_time_n and cp_time_o on FreeBSD and DragonFlyBSD #873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
A similar change might be necessary for other BSD variants too. Can you have a look and include the necessary changes too? |
freebsd/FreeBSDProcessList.c
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CPU_STATES
-> CPUSTATES
in the suggested change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.