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

Prevent race collisions when parsing FTL config file #1222

Merged
merged 2 commits into from Oct 17, 2021

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Oct 17, 2021

By submitting this pull request, I confirm the following:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?:

10


Fixes #1214. So far, memory was released whenever an operation was finished, however, we've seen a race collision where releasing the memory happened too early.

We address this in two ways:

  1. Guard the config parsing in a mutex-protected section, ensuring only one thread can do this at the same time, and
  2. do not free the config line memory after having used it.

As we need to read the config file every now and then (e.g., checking the privacy level) we can also just keep the memory instead of always getting "fresh" memory. This buys us some (very small) speed advantage at the costs of a few dozen bytes additional memory usage. This shouldn't be an issue in 2021.

…e overall memory consumption of FTL by a about 100 bytes, however, we do not need to allocate andfree when re-reading any runtime config lines (privacy mode, etc.).

Signed-off-by: DL6ER <dl6er@dl6er.de>
…collisions

Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER added the Bugfix label Oct 17, 2021
@DL6ER DL6ER requested a review from yubiuser October 17, 2021 08:44
@DL6ER DL6ER linked an issue Oct 17, 2021 that may be closed by this pull request
@DL6ER DL6ER merged commit 71dc412 into development Oct 17, 2021
@DL6ER DL6ER deleted the fix/linebuffer_freeing branch October 17, 2021 18:56
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-ftl-v5-11-web-v5-8-and-core-v5-6-released/50566/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FTL crashed while importing Teleporter backup
3 participants