[clang] Adding support for NSMakeCollectable and CFMakeCollectable

Summary:
@public
Adding support for NSMakeCollectable and CFMakeCollectable.
Fixes issue https://github.com/facebook/infer/issues/116

Test Plan:
Tested on the example of the issue https://github.com/facebook/infer/issues/116
and we don't get the leak there anymore.
master
Dulma Rodriguez 10 years ago
parent 9f9bc53361
commit ea3e614cce

@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>
CFTypeRef CFMakeCollectable ( CFTypeRef cf ) {
return cf;
}

@ -106,6 +106,8 @@ let cf_bridging_retain = "CFBridgingRetain"
let cf_autorelease = "CFAutorelease"
let ns_make_collectable = "NSMakeCollectable"
let builtin_expect = "__builtin_expect"
let builtin_memset_chk = "__builtin___memset_chk"

@ -103,6 +103,8 @@ val cf_bridging_retain : string
val cf_autorelease : string
val ns_make_collectable : string
val builtin_expect : string
val builtin_memset_chk : string

@ -90,7 +90,8 @@ let is_toll_free_bridging pn_opt =
let funct = (Procname.to_string pn) in
funct = CFrontend_config.cf_bridging_release ||
funct = CFrontend_config.cf_bridging_retain ||
funct = CFrontend_config.cf_autorelease
funct = CFrontend_config.cf_autorelease ||
funct = CFrontend_config.ns_make_collectable
| None -> false
(** If the function is a builtin model, return the model, otherwise return the function *)

@ -0,0 +1,19 @@
#import <Foundation/Foundation.h>
@interface E : NSObject
@end
@implementation E
- (CFReadStreamRef) readStream {
return nil;
}
- (void) handleStreamError
{
NSError *underlyingError = NSMakeCollectable(
[(NSError*)CFReadStreamCopyError((CFReadStreamRef)[self readStream]) autorelease]);
}
@end

@ -0,0 +1,62 @@
/*
* Copyright (c) 2013- Facebook.
* All rights reserved.
*/
package endtoend.objc;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class NSMakeCollectableTest {
public static final String memory_leak_file =
"infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/NSMakeCollectableExample.m";
private static ImmutableList<String> inferCmd;
public static final String MEMORY_LEAK = "MEMORY_LEAK";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCInferCommandWithMLBuckets(
folder,
memory_leak_file,
"cf",
false);
}
@Test
public void whenInferRunsOnTestWithBucketingThenMLIsNotFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
String[] procedures = {
};
assertThat(
"Results should not contain memory leak",
inferResults,
containsExactly(
MEMORY_LEAK,
memory_leak_file,
procedures));
}
}
Loading…
Cancel
Save