Mailing List Archive

[Bug 68553] Memory leak detected when using httpd as a reverse proxy on Windows
https://bz.apache.org/bugzilla/show_bug.cgi?id=68553

Shigeharu Yamamoto <yamamoto.shi-02@fujitsu.com> changed:

What |Removed |Added
----------------------------------------------------------------------------
Component|mod_proxy |APR
Assignee|bugs@httpd.apache.org |bugs@apr.apache.org
Product|Apache httpd-2 |APR
Version|2.4.57 |1.7.4
OS| |All

--- Comment #1 from Shigeharu Yamamoto <yamamoto.shi-02@fujitsu.com> ---
We identified the factor that causes memory leaks on Windows but not on Linux.
As a result, we determined that the Windows memory leak was caused by the Linux
fix (*) not being reflected in Windows.
Tell us what the community thinks about whether that determine is correct.
The details are described below.


[Location of cause]
The difference in the apr_sockaddr_ip_get function
(apr_sockaddr_ip_get(&c->client_ip, c->client_addr)) specifying the area to
hold the IP address string was caused by the following difference in the
apr_socket_connect function:
The following processing was identical to Windows (sock->remote_addr = sa)
before APR1.4.2 on Linux, but was fixed between APR1.4.2 and 1.4.4 on Linux
only and not on Windows.
[Windows]
https://github.com/apache/apr/blob/1.7.4/network_io/win32/sockets.c#L416
/* Copy the address structure details in. */
sock->remote_addr = sa;
[Linux](*)
https://github.com/apache/apr/blob/1.7.4/network_io/unix/sockets.c#L429
/* Copy the address structure details in. */
sock->remote_addr->sa = sa->sa;
sock->remote_addr->salen = sa->salen;
/* Adjust ipaddr_ptr et al. */
apr_sockaddr_vars_set(sock->remote_addr, sa->family, sa->port);
[Process]
On Windows, the apr_socket_connect function does not use
sock->remote_addr(newsock->remote_addr allocated to scpool by alloc_socket
function in apr_socket_create function) and replaces it with the address of sa,
an apr_sockaddr_t structure in dns_pool.
As a result, sock->remote_addr->pool becomes dns_pool, and the
apr_sockaddr_ip_get function stores the IP address string in dns_pool.
This causes additional client_ip to be stored in the dns_pool each time a
TCP/IP connection is made, and the space is kept until the end of the child
process, thus leaking memory.
However, Linux uses sock->remote_addr(newsock->remote_addr allocated to scpool
by alloc_socket function in apr_socket_create function) as is, and copies only
the union (sa->sa) part of the apr_sockaddr_t structure in dns_pool, such as
sockaddr_in/sockaddr_in6.
As a result, sock->remote_addr->pool remain as scpool, and the
apr_sockaddr_ip_get function stores the IP address string in scpool.
However, scpool does not leak memory because it is initialized for every TCP/IP
connection.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org