Skip to content

Fix resource leaks in msc_status_engine_mac_address #3391

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

Merged
merged 1 commit into from
Jun 7, 2025

Conversation

amezin
Copy link
Contributor

@amezin amezin commented May 27, 2025

what

Close the socket created and free the memory allocated in msc_status_engine_mac_address() in all code paths.

why

Linux:

The socket is used only temporarily. Current implementation leaks the socket. For example, if SecRemoteRules is used anywhere in the config, systemctl reload httpd/systemctl reload apache2 increases the count of open sockets in all Apache processes (well, it happens in the main process, and forked ones just inherit the problem).

Other platforms:

goto end just jumped over the calls freeing the memory.

references

@amezin
Copy link
Contributor Author

amezin commented May 27, 2025

Hm... After looking a bit more, there seems to be a leak on all platforms. But on Windows and Mac, it's just a memory leak. Maybe goto end should be replaced by break everywhere?

`goto end` jumped over freeing/releasing resources for all platforms.

For Linux, this caused a leak of open socket. For other platforms, it's
just a memory leak.
@amezin amezin changed the title Fix socket leak in msc_status_engine_mac_address Fix resource leaks in msc_status_engine_mac_address May 27, 2025
Copy link

@airween
Copy link
Member

airween commented May 27, 2025

Hi @amezin,

Hm... After looking a bit more, there seems to be a leak on all platforms. But on Windows and Mac, it's just a memory leak. Maybe goto end should be replaced by break everywhere?

I can check this next weekend. I'll try to add some test to check this PR (or feel free to add some - see .github directory).

@amezin
Copy link
Contributor Author

amezin commented May 27, 2025

BTW v3 also has the same issue - #3392 - because the code (for mac address retrieval) is mostly the same

As far as I understand, there are windows/mac tests on v3

@airween
Copy link
Member

airween commented Jun 7, 2025

BTW v3 also has the same issue - #3392 - because the code (for mac address retrieval) is mostly the same

Thanks again,

As far as I understand, there are windows/mac tests on v3

Yes, v3 has an excellent test framework (but that's a library). And these tests can be run on any platform where the library can be built. In GH workflow, we run the tests on Linux (32 and 64 bit), Mac OSX and Windows.

I'm going to merge this PR - thanks again!

@airween airween merged commit 061fade into owasp-modsecurity:v2/master Jun 7, 2025
82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants