Skip to content
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

Merged
merged 5 commits into from
Jan 5, 2017
Merged

Don't leak or race in FreeBSD devstat collector #396

merged 5 commits into from
Jan 5, 2017

Conversation

dominikh
Copy link
Contributor

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.

@discordianfish
Copy link
Member

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?

@dominikh
Copy link
Contributor Author

dominikh commented Jan 3, 2017

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.
@dominikh
Copy link
Contributor Author

dominikh commented Jan 5, 2017

@discordianfish PTAL

@@ -0,0 +1,66 @@
// +build !nodevstat
Copy link
Member

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.

Copy link
Member

@grobie grobie left a 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
Copy link
Member

@dominikh Great! Can you add the license header as @grobie asked? Then I can merge this later today.

@dominikh
Copy link
Contributor Author

dominikh commented Jan 5, 2017

@discordianfish Already done in 9847257

@discordianfish
Copy link
Member

Gna.. github.. Thanks!

@discordianfish discordianfish merged commit fc1113c into prometheus:master Jan 5, 2017
@SuperQ SuperQ mentioned this pull request Jan 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants