Skip to content

Commit

Permalink
Ignore run_loop when leak sanitizer is enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Jan 18, 2024
1 parent 5c0f452 commit 6bd9ac0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions resolver_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "resolver_mac.h"
#include "util.h"

#ifdef LEAK_SANITIZER
# include <sanitizer/lsan_interface.h>
#endif

#define PROXY_RESOLVER_RUN_LOOP CFSTR("proxy_resolver_mac.run_loop")
#define PROXY_RESOLVER_TIMEOUT_SEC 10

Expand Down Expand Up @@ -158,6 +162,15 @@ bool proxy_resolver_mac_get_proxies_for_url(void *ctx, const char *url) {

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

CFRunLoopSourceRef run_loop = CFNetworkExecuteProxyAutoConfigurationURL(
url_ref, target_url_ref, proxy_resolver_mac_auto_config_result_callback, &context);
if (!run_loop) {
proxy_resolver->error = ELOOP;
LOG_ERROR("Failed to execute pac url (%" PRId64 ")\n", proxy_resolver->error);
goto mac_done;
}

#ifdef LEAK_SANITIZER
// There is a known issue mentioned in Chromium source, that the run loop instance
// returned by CFNetworkExecuteProxyAutoConfigurationURL leaks.

Expand All @@ -166,13 +179,9 @@ bool proxy_resolver_mac_get_proxies_for_url(void *ctx, const char *url) {
// https://forums.developer.apple.com/forums/thread/724883
// https://stackoverflow.com/questions/53290871

CFRunLoopSourceRef run_loop = CFNetworkExecuteProxyAutoConfigurationURL(
url_ref, target_url_ref, proxy_resolver_mac_auto_config_result_callback, &context);
if (!run_loop) {
proxy_resolver->error = ELOOP;
LOG_ERROR("Failed to execute pac url (%" PRId64 ")\n", proxy_resolver->error);
goto mac_done;
}
__lsan_ignore_object(run_loop);
#endif

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 6bd9ac0

Please sign in to comment.