Skip to content

CFG: @​finally code is executed for any 'exit' from a @​try block #4324

@llvmbot

Description

@llvmbot
Bugzilla Link 3952
Resolution FIXED
Resolved on Oct 27, 2016 02:02
Version unspecified
OS All
Attachments Project demonstrating the problem.
Reporter LLVM Bugzilla Contributor
CC @tkremenek

Extended Description

This may or may not be related to http://llvm.org/bugs/show_bug.cgi?id=3888; I'm not clang-savvy enough to know for sure.

Code like the following will falsely warn that 'obj' is leaked:

NSObject *obj = [[NSObject alloc] init];
@​try {
    return nil;
} @​catch (NSException *exc) {
    [obj release];
    obj = nil;
    [exc raise];
} @​finally {
    [obj release];
}

return nil;

But both the @​catch and @​finally block clean it up. Really only the @​finally is needed, but this example was trimmed from code that needed different cleanup on both paths. The assignment obj=nil avoids @​finally hitting a zombie.

Attached a full Xcode project that can be used with scan-build to show the problem.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions