-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Don't leak or race in FreeBSD devstat collector #396
Conversation
Oh great, thanks! Unfortunately I've just merged a PR to change the metrics to const metrics so some conflicts need to be resolved. Can you rebase this? |
Sure, will do tomorrow. |
The memory allocated by calloc was never freed. Since the devinfo struct never leaves the function, anyway, we might as well just allocate it on the stack.
Embedding 100 lines of code in a comment doesn't make for good reading, editing or code quality.
Querying the number of devices separately from the device list itself is racy. Devices may be added or removed between the two calls; and removed devices would lead to a segfault.
The devstat API expects us to reuse one devinfo for many invocations of devstat_getstats. In particular, it allocates and resizes memory referenced by devinfo.
@discordianfish PTAL |
@@ -0,0 +1,66 @@ | |||
// +build !nodevstat |
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.
Please include our license header at the top.
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.
Haven't looked at the C code, but I trust you tested it.
@discordianfish Already done in 9847257 |
Gna.. github.. Thanks! |
The FreeBSD devstat collector was leaking memory (calloc with no matching free as well as memory allocated by devstat_getdevs). It was also racing, by querying the number of devices and the actual list of devices separately.
The same flaws exist in the DragonflyBSD collector. Someone with access to a machine for testing might want to port the fixes over.