[pulse] Add model for NSObject.init

Summary:
This model is very important in the analysis of ObjC classes because the pattern

```
- (instancetype)init {
  if (self = [super init]) {
    ...
  }
  return self;
}

```

is very common, so we need to know that if the super class is `NSObject`, the implementation of `init` is returning `self`, otherwise it's a skip function and we don't get the correct spec for the function.  We fix some memory leak FP with this model, see test.

Reviewed By: ezgicicek

Differential Revision: D22259281

fbshipit-source-id: 3ee48c827
master
Dulma Churchill 4 years ago committed by Facebook GitHub Bot
parent 2c48e61031
commit 85ee958bf9

@ -985,7 +985,8 @@ module ProcNameDispatcher = struct
; -"CFBridgingRelease" <>$ capt_arg_payload $--> ObjCCoreFoundation.cf_bridging_release
; +match_builtin BuiltinDecl.__objc_bridge_transfer
<>$ capt_arg_payload $--> ObjCCoreFoundation.cf_bridging_release
; +match_builtin BuiltinDecl.__objc_alloc_no_fail <>$ capt_exp $--> ObjC.alloc_not_null ] )
; +match_builtin BuiltinDecl.__objc_alloc_no_fail <>$ capt_exp $--> ObjC.alloc_not_null
; -"NSObject" &:: "init" <>$ capt_arg_payload $--> Misc.id_first_arg ] )
end
let dispatch tenv proc_name args = ProcNameDispatcher.dispatch tenv proc_name args

@ -0,0 +1,32 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <Foundation/NSObject.h>
#include <stdlib.h>
@interface MyBufferContainer : NSObject
@property char* buffer;
@end
@implementation MyBufferContainer
- (instancetype)init {
if (self = [super init]) {
_buffer = malloc(sizeof(char));
}
return self;
}
- (void)dealloc {
free(_buffer);
}
@end
void raii_no_leak_ok() {
MyBufferContainer* b = [[MyBufferContainer alloc] init];
}
Loading…
Cancel
Save