Skip to content

Update php_dns.h - fixes memory leak. #1736

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

Closed
wants to merge 1 commit into from
Closed

Update php_dns.h - fixes memory leak. #1736

wants to merge 1 commit into from

Conversation

zaydogan
Copy link

You need to call res_ndestroy() to free memory, otherwise you will leak a file descriptor on NetBSD or leak memory on FreeBSD and other operating systems. Please see the resolver man page at: http://man.netbsd.org/cgi-bin/man-cgi?resolver++NetBSD-current
"res_ndestroy() should be called to free memory allocated by res_ninit() after last use.".
I found the bug on NetBSD 7.0 with php 7.0.2, but it also affects php 5.6.14 and probably previous versions.
Here is a test-script to reproduce the memory leak:

You need to call res_ndestroy() to free memory, otherwise you will leak a file descriptor on NetBSD or leak memory on FreeBSD and other operating systems. Please see the resolver man page at: http://man.netbsd.org/cgi-bin/man-cgi?resolver++NetBSD-current
"res_ndestroy() should be called to free memory allocated by res_ninit() after last use.".
I found the bug on NetBSD 7.0 with php 7.0.2, but it also affects php 5.6.14 and probably previous versions.
Here is a test-script to reproduce the memory leak:
<?php
for ($i = 0; $i < 50000; $i++) {
        echo $i . ": ";
        var_dump(checkdnsrr("www.netbsd.org", "A"));
}
While running this script, have a look how the php process grows because of the memory leak.
@laruence laruence added the Bug label Jan 22, 2016
@nikic
Copy link
Member

nikic commented Jan 29, 2016

The Travis build fails to compile due to an undefined res_ndestroy symbol.

@zaydogan
Copy link
Author

I see. Not all res_n* functions are implemented in Linux. We need a feature test then for res_ndestroy. This also means that it leaks only on platforms that implement res_ndestroy. (All *BSD's, Illumos (Solaris) and MacOS).

@weltling
Copy link
Contributor

weltling commented Nov 9, 2016

@zaydogan any progress on this? I could test on FreeBSD once it's implemented.

Thanks.

@krakjoe
Copy link
Member

krakjoe commented Jan 1, 2017

@zaydogan bump .... some action would be good ;)

@zaydogan
Copy link
Author

zaydogan commented Jan 1, 2017 via email

@krakjoe
Copy link
Member

krakjoe commented Jan 1, 2017

@zaydogan Any reason why the patch hasn't been prepared to implement change for those operating systems only ?

@zaydogan
Copy link
Author

zaydogan commented Jan 1, 2017 via email

@krakjoe
Copy link
Member

krakjoe commented Jan 1, 2017

@weltling can I request that you pick this up please ?

@weltling
Copy link
Contributor

weltling commented Jan 2, 2017

@krakjoe noted, thanks for the ping.

@weltling weltling self-assigned this Jan 2, 2017
php-pulls pushed a commit that referenced this pull request Jan 7, 2017
This fixes leak issues on *BSD systems, as described in the PR.
php-pulls pushed a commit that referenced this pull request Jan 7, 2017
* PHP-7.0:
  Implement github PR #1736
php-pulls pushed a commit that referenced this pull request Jan 7, 2017
* PHP-7.1:
  Implement github PR #1736
@weltling
Copy link
Contributor

weltling commented Jan 7, 2017

Implemented with 486fc04. @zaydogan please test.

Thanks.

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.

5 participants