Use scoped_nsobject to ensure our intermediate objects get cleaned up.
authorCharlie Hess <charlie@slack-corp.com>
Wed, 4 May 2016 18:28:49 +0000 (11:28 -0700)
committerCharlie Hess <charlie@slack-corp.com>
Wed, 4 May 2016 18:28:49 +0000 (11:28 -0700)
atom/browser/browser_mac.mm
atom/browser/mac/atom_application.h
atom/browser/mac/atom_application.mm
atom/browser/mac/atom_application_delegate.mm

index 0695793..42d10de 100644 (file)
@@ -91,16 +91,16 @@ void Browser::SetUserActivity(const std::string& type, const std::map<std::strin
   NSString* type_ns = [NSString stringWithUTF8String:type.c_str()];
   NSUserActivity* user_activity = [[NSUserActivity alloc] initWithActivityType:type_ns];
 
-  NSMutableDictionary* user_info_args = [[NSMutableDictionary alloc] init];
+  base::scoped_nsobject<NSMutableDictionary> user_info_args([[NSMutableDictionary alloc] init]);
   for (auto const &pair : user_info) {
     NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()];
     NSString* key_ns = [NSString stringWithUTF8String:pair.first.c_str()];
 
-    [user_info_args setObject:value_ns
-                       forKey:key_ns];
+    [user_info_args.get() setObject:value_ns
+                             forKey:key_ns];
   }
 
-  user_activity.userInfo = user_info_args;
+  user_activity.userInfo = user_info_args.get();
   [user_activity becomeCurrent];
 
   [[AtomApplication sharedApplication] setCurrentActivity:user_activity];
index e31a992..37074ca 100644 (file)
@@ -3,12 +3,13 @@
 // found in the LICENSE file.
 
 #import "base/mac/scoped_sending_event.h"
+#import "base/mac/scoped_nsobject.h"
 
 @interface AtomApplication : NSApplication<CrAppProtocol,
                                            CrAppControlProtocol> {
  @private
   BOOL handlingSendEvent_;
-  NSUserActivity* currentActivity_;
+  base::scoped_nsobject<NSUserActivity> currentActivity_;
 }
 
 + (AtomApplication*)sharedApplication;
index 3fe6658..1811511 100644 (file)
 }
 
 - (void)setCurrentActivity:(NSUserActivity*)userActivity {
-  currentActivity_ = userActivity;
+  currentActivity_ = base::scoped_nsobject<NSUserActivity>(userActivity);
 }
 
 - (NSUserActivity*)getCurrentActivity {
-  return currentActivity_;
+  return currentActivity_.get();
 }
 
 - (void)awakeFromNib {
index 2309a75..0904679 100644 (file)
@@ -65,9 +65,9 @@ continueUserActivity:(NSUserActivity *)userActivity
   std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
 
   std::map<std::string, std::string> user_info;
+  base::scoped_nsobject<NSArray> keys([userActivity.userInfo allKeys]);
 
-  NSArray* keys = [userActivity.userInfo allKeys];
-  for (NSString* key in keys) {
+  for (NSString* key in keys.get()) {
     NSString* value = [userActivity.userInfo objectForKey:key];
     std::string key_str(base::SysNSStringToUTF8(key));
     std::string value_str(base::SysNSStringToUTF8(value));