Skip to content

REGRESSION: ObjC objects passed to C++ 'new' are still retain-count-tracked #11166

@belkadan

Description

@belkadan
Bugzilla Link 10794
Resolution FIXED
Resolved on Mar 16, 2012 21:40
Version trunk
OS All

Extended Description

Currently, RetainReleaseChecker is supposed to stop tracking the retain counts of objects that are passed to C++ methods, or generally into C++-land, at least until we've established what the right behavior should be. This works for regular methods and for stack constructors, but not for heap constructors, i.e. C++ objects allocated with 'new'.

Previously this worked almost coincidentally; /every/ argument's retain count was invalidated /except/ those explicitly whitelisted by the CFRefCount transfer functions. And CFRefCount never handled C++-only expressions anyway.

One fix is as follows:

  1. Add CXXNewExpr to CallOrObjCMessage.
  2. Add a post-statement hook for CXXNewExpr.
  3. Implement check::PostStmt on RetainReleaseChecker with the exact same code as for CXXConstructExprs.

This change occurred (deliberately) in r138716.

Test case (for retain-release.mm):

void test_smartpointer_4() {
id x = [[NSObject alloc] init]; // no-warning
SmartPointer *foo = new SmartPointer(x);
delete foo;
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions