Commit 856bcc0a9277fc8e9f99af073e36a4d986fdec6d
1 parent
31ddd2c7
fix(connection): resolve() leaks memory when connection can't be made
Showing
1 changed file
with
7 additions
and
0 deletions
src/Connection.cpp
| ... | ... | @@ -125,6 +125,13 @@ void Connection::resolve() |
| 125 | 125 | hints.ai_socktype = SOCK_STREAM; |
| 126 | 126 | hints.ai_flags = AI_ADDRCONFIG; |
| 127 | 127 | |
| 128 | + // If we resolved previously, free the result. | |
| 129 | + if (this->m_host_resolved != nullptr) | |
| 130 | + { | |
| 131 | + freeaddrinfo(this->m_host_resolved); | |
| 132 | + this->m_host_resolved = nullptr; | |
| 133 | + } | |
| 134 | + | |
| 128 | 135 | // Request the OS to resolve the hostname into an IP address. |
| 129 | 136 | // We do this even if the hostname is already an IP address, as that |
| 130 | 137 | // makes for far easier code. | ... | ... |