swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.3k stars 1.14k forks source link

[SR-6391] Repeated invocation of `ProcessInfo.hostname` causes unbounded heap growth #4057

Open swift-ci opened 7 years ago

swift-ci commented 7 years ago
Previous ID SR-6391
Radar None
Original Reporter swizzlr (JIRA User)
Type Bug
Status In Progress
Resolution
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | swizzlr (JIRA) | |Priority | Medium | md5: eb2a2f92784172873e4d6e8c88472cf1

Issue Description:

This was a fun bug to track down. `massif` is amazing, tho.

https://github.com/apple/swift-corelibs-foundation/blob/swift-4.0-branch/Foundation/Host.swift#L85 is the line where _addresses is appended to with a string.

_resolveCurrent() is called by _resolve() when `_resolved` is set to false. The bug is here: `_resolved` is, as far as I can tell, never set to `true`.

_resolve() is called in the `names` getter; the `names` getter is called by `name`'s getter, which is called by ProcessInfo.hostname against the `Host.current()` object.

Fix is to set _resolved to `true` after `_resolveCurrent()` succeeds.

Workaround is to cache the hostname elsewhere.

swift-ci commented 7 years ago

Comment by Thomas Catterall (JIRA)

https://github.com/apple/swift-corelibs-foundation/pull/1320