Skip to content

Commit

Permalink
Attempt to call CFNetworkCopyProxiesForURL to mitigate leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Jan 18, 2024
1 parent c3eb534 commit 9bafd64
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions resolver_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ bool proxy_resolver_mac_get_proxies_for_url(void *ctx, const char *url) {
goto mac_done;
}

// There is a known issue mentioned in Chromium source, that the run loop instance
// returned by CFNetworkExecuteProxyAutoConfigurationURL leaks. (rdar://problem/5530166)

// Additionally it is discussed on these forums:
// http://www.openradar.appspot.com/20974299
// https://forums.developer.apple.com/forums/thread/724883

// The workaround is to first call CFNetworkCopyProxiesForURL to initialize the CFNetwork state.

CFArrayRef ignore = CFNetworkCopyProxiesForURL(target_url_ref, NULL);
if (ignore)
CFRelease(ignore);

CFStreamClientContext context = {0, proxy_resolver, NULL, NULL, NULL};

CFRunLoopSourceRef run_loop = CFNetworkExecuteProxyAutoConfigurationURL(
Expand All @@ -165,12 +178,6 @@ bool proxy_resolver_mac_get_proxies_for_url(void *ctx, const char *url) {
LOG_ERROR("Failed to execute pac url (%" PRId64 ")\n", proxy_resolver->error);
goto mac_done;
}

// According to Chromium comments, the run loop instance returned by
// CFNetworkExecuteProxyAutoConfigurationURL leaks.
// http://www.openradar.appspot.com/20974299
// https://forums.developer.apple.com/forums/thread/724883

CFRunLoopAddSource(CFRunLoopGetCurrent(), run_loop, PROXY_RESOLVER_RUN_LOOP);
CFRunLoopRunInMode(PROXY_RESOLVER_RUN_LOOP, PROXY_RESOLVER_TIMEOUT_SEC, false);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop, PROXY_RESOLVER_RUN_LOOP);
Expand Down

0 comments on commit 9bafd64

Please sign in to comment.