@@ -36,6 +36,7 @@ @interface FlutterObservatoryPublisher () <NSNetServiceDelegate>
3636@end
3737
3838@implementation FlutterObservatoryPublisher {
39+ fml::scoped_nsobject<NSURL > _url;
3940#if TARGET_IPHONE_SIMULATOR
4041 DNSServiceRef _dnsServiceRef;
4142#else // TARGET_IPHONE_SIMULATOR
@@ -46,6 +47,10 @@ @implementation FlutterObservatoryPublisher {
4647 std::unique_ptr<fml::WeakPtrFactory<FlutterObservatoryPublisher>> _weakFactory;
4748}
4849
50+ - (NSURL *)url {
51+ return _url.get ();
52+ }
53+
4954- (instancetype )init {
5055 self = [super init ];
5156 NSAssert (self, @" Super must not return null on init." );
@@ -92,15 +97,14 @@ - (void)publishServiceProtocolPort:(std::string)uri {
9297 }
9398 // uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port
9499 // number.
95- NSURL * url =
96- [[[NSURL alloc ] initWithString: [NSString stringWithUTF8String: uri.c_str ()]] autorelease ];
100+ _url.reset ([[NSURL alloc ] initWithString: [NSString stringWithUTF8String: uri.c_str ()]]);
97101
98102 NSString * serviceName =
99103 [[[NSBundle mainBundle ] infoDictionary ] objectForKey: @" CFBundleIdentifier" ];
100104
101105 // Check to see if there's an authentication code. If there is, we'll provide
102106 // it as a txt record so flutter tools can establish a connection.
103- auto path = std::string{[[url path ] UTF8String ]};
107+ auto path = std::string{[[_url path ] UTF8String ]};
104108 if (!path.empty ()) {
105109 // Remove leading "/"
106110 path = path.substr (1 );
@@ -116,7 +120,7 @@ - (void)publishServiceProtocolPort:(std::string)uri {
116120 uint32_t interfaceIndex = if_nametoindex (" lo0" );
117121 const char * registrationType = " _dartobservatory._tcp" ;
118122 const char * domain = " local." ; // default domain
119- uint16_t port = [[url port ] intValue ];
123+ uint16_t port = [[_url port ] intValue ];
120124
121125 int err = DNSServiceRegister (&_dnsServiceRef, flags, interfaceIndex, [serviceName UTF8String ],
122126 registrationType, domain, NULL , htons (port), txtData.length ,
@@ -131,7 +135,7 @@ - (void)publishServiceProtocolPort:(std::string)uri {
131135 NSNetService * netServiceTmp = [[NSNetService alloc ] initWithDomain: @" local."
132136 type: @" _dartobservatory._tcp."
133137 name: serviceName
134- port: [[url port ] intValue ]];
138+ port: [[_url port ] intValue ]];
135139 [netServiceTmp setTXTRecordData: txtData];
136140 _netService.reset (netServiceTmp);
137141 [_netService.get () setDelegate: self ];
0 commit comments