Fix C functions and C++ methods returning retained Cocoa objects |
||||
Issue descriptionThere are C functions and C++ methods in Chromium that return retained Cocoa object pointers. If such a function is built with MRR, and is called from a file built with ARC, the returned object will leak. There are two ways to work around that: * mark functions as NS_RETURNS_RETAINED * modify functions to return an autoreleased object instead. Modify callers accordingly.
,
Aug 10 2016
Annotator code for C functions:
void CfuncannotatorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl().bind("x"), this);
}
void CfuncannotatorCheck::check(const MatchFinder::MatchResult &Result) {
// FIXME: Add callback implementation.
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("x");
QualType returnType =MatchedDecl->getReturnType();
if (!returnType->isObjCObjectPointerType())
return;
diag(MatchedDecl->getLocation(), "function %0 is returning a cocoa object")
<< MatchedDecl
<< FixItHint::CreateInsertion(MatchedDecl->getLocation(), "cocoareturner_");
}
,
Aug 10 2016
There are 678 C functions, returning ObjC object pointers. I need to see if I can automatically detect those returning a retained object.
,
Aug 16 2016
+rohitrao: You asked me on https://chromereviews.googleplex.com/484417013/ how did I derive the list of functions to review.
,
Aug 17 2016
These functions should be fixed: from being annotated they should be changed to actually returning scoped_nsobjects or autoreleased objects. This will involve fixing all call sites, too.
,
Aug 18 2016
The following revision refers to this bug: https://chrome-internal.googlesource.com/chrome/ios_internal.git/+/ba167c719f70ff7ae9fc3247ff04161d368250d8 commit ba167c719f70ff7ae9fc3247ff04161d368250d8 Author: stkhapugin <stkhapugin@google.com> Date: Thu Aug 18 12:40:25 2016
,
Aug 19 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/1f03171454f9041019b56399a5b6752e559b5429 commit 1f03171454f9041019b56399a5b6752e559b5429 Author: stkhapugin <stkhapugin@chromium.org> Date: Fri Aug 19 12:08:22 2016 Annotates functions returning retained objects. Annotates all C functions and C++ methods returning retained Cocoa objects with NS_RETURNS_RETAINED annotation. This annotation is no-op without ARC, and with ARC it ensures correct memory management. More about this annotation: http://clang-analyzer.llvm.org/annotations.html#attr_ns_returns_retained More information about the process behind this cl on the bug. BUG= 636375 Review-Url: https://codereview.chromium.org/2239773002 Cr-Commit-Position: refs/heads/master@{#413113} [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/components/signin/ios/browser/account_consistency_service.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/chrome/browser/signin/gaia_auth_fetcher_ios_private.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/public/provider/chrome/browser/chrome_browser_provider.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/public/provider/chrome/browser/geolocation_updater_provider.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/public/provider/chrome/browser/updatable_resource_provider.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/web/public/web_view_creation_util.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/web/test/wk_web_view_crash_utils.h [modify] https://crrev.com/1f03171454f9041019b56399a5b6752e559b5429/ios/web/web_state/web_view_internal_creation_util.h
,
Apr 12 2017
,
Aug 17 2017
|
||||
►
Sign in to add a comment |
||||
Comment 1 by stkhapugin@chromium.org
, Aug 10 2016