Commit a872654a authored by aestes@apple.com's avatar aestes@apple.com

Fix issues found by the Clang Static Analyzer

https://bugs.webkit.org/show_bug.cgi?id=120230

Reviewed by Darin Adler.

Source/JavaScriptCore:

* API/JSValue.mm:
(valueToString): Don't leak every CFStringRef when in Objective-C GC.
* API/ObjCCallbackFunction.mm:
(JSC::ObjCCallbackFunctionImpl::~ObjCCallbackFunctionImpl): Don't
release m_invocation's target since NSInvocation will do it for us on
-dealloc.
(objCCallbackFunctionForBlock): Tell NSInvocation to retain its target
and -release our reference to the copied block.
* API/tests/minidom.c:
(createStringWithContentsOfFile): Free buffer before returning.
* API/tests/testapi.c:
(createStringWithContentsOfFile): Ditto.

Source/WebCore:

* WebCore.xcodeproj/project.pbxproj: Removed FoundationExtras.h.
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm: Removed CFAutoreleaseHelper().
(AXTextMarkerRange): Used HardAutorelease() instead of
CFAutoreleaseHelper().
(AXTextMarkerRangeStart): Ditto.
(AXTextMarkerRangeEnd): Ditto.
(textMarkerForVisiblePosition): Ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(-[WebCoreAVFMovieObserver initWithCallback:]): Called [super init]
first so that we don't later use ivars from the wrong self.
(-[WebCoreAVFLoaderDelegate initWithCallback:]): Ditto.
* platform/mac/FoundationExtras.h: Removed.
* platform/mac/KURLMac.mm:
(WebCore::KURL::operator NSURL *): Used WTF's HardAutorelease().
* platform/mac/WebCoreNSURLExtras.mm:
(WebCore::mapHostNameWithRange): Used HardAutorelease() instead of
WebCoreCFAutorelease().
(WebCore::URLWithData): Ditto.
(WebCore::userVisibleString): Ditto.
(WebCore::URLByRemovingComponentAndSubsequentCharacter): Used Vector<>
with an inline capacity rather than heap-allocating a buffer.
* platform/mac/WebCoreObjCExtras.h: Used HardAutorelease() instead of
WebCoreCFAutorelease().
* platform/text/mac/StringImplMac.mm:
(WTF::StringImpl::operator NSString *): Used WTF's HardAutorelease().

Source/WebKit/mac:

* Misc/WebNSFileManagerExtras.mm:
(-[NSFileManager _webkit_startupVolumeName]): Used HardAutorelease()
instead of WebCFAutorelease().
* Misc/WebNSObjectExtras.h: Removed definition of WebCFAutorelease().
* Misc/WebNSURLExtras.mm:
(-[NSURL _web_URLWithLowercasedScheme]): Used HardAutorelease()
instead of WebCFAutorelease().
* Plugins/Hosted/WebHostedNetscapePluginView.mm:
(-[WebHostedNetscapePluginView createPluginLayer]): Stop leaking
CGColors (CALayer retains its backgroundColor property despite the
property attributes claiming otherwise).
* Plugins/WebBasePluginPackage.mm:
(+[WebBasePluginPackage preferredLocalizationName]): Used
HardAutorelease() instead of WebCFAutorelease().
* WebView/WebDeviceOrientationProviderMock.mm:
(-[WebDeviceOrientationProviderMockInternal lastOrientation]): Stop
leaking WebDeviceOrientations.
* WebView/WebPDFRepresentation.mm:
(-[WebPDFRepresentation convertPostScriptDataSourceToPDF:]): Used
HardAutorelease() instead of WebCFAutorelease().
* WebView/WebView.mm:
(+[WebView _setCacheModel:]): Ditto.
(-[WebView _removeObjectForIdentifier:]): Ditto.

Source/WebKit2:

* UIProcess/API/mac/WKBrowsingContextController.mm:
(autoreleased): Don't leak CFURLs when in Objective-C GC.
* WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm:
(-[WKAccessibilityWebPageObject accessibilityAttributeValue:forParameter:]):
Don't leak CFStrings when in Objective-C GC.

Source/WTF:

* wtf/ObjcRuntimeExtras.h:
(HardAutorelease): Added a canonical implementation of HardAutorelease.

Tools:

* DumpRenderTree/mac/DumpRenderTreePasteboard.m:
(-[LocalPasteboard initWithName:]): Called [super init] first so that we
don't later use ivars from the wrong self.
* DumpRenderTree/mac/TestRunnerMac.mm:
(-[APITestDelegate initWithCompletionCondition:]): Ditto.
* TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm:
(TestWebKitAPI::TEST): Don't leak WKProcessGroups,
WKBrowsingContextGroups, and WKViews.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154647 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fffbb73f
......@@ -39,6 +39,7 @@
#import "JSCJSValue.h"
#import <wtf/HashMap.h>
#import <wtf/HashSet.h>
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/Vector.h>
#import <wtf/TCSpinLock.h>
#import <wtf/text/WTFString.h>
......@@ -745,7 +746,7 @@ id valueToString(JSGlobalContextRef context, JSValueRef value, JSValueRef* excep
return nil;
}
NSString *stringNS = [(NSString *)JSStringCopyCFString(kCFAllocatorDefault, jsstring) autorelease];
NSString *stringNS = HardAutorelease(JSStringCopyCFString(kCFAllocatorDefault, jsstring));
JSStringRelease(jsstring);
return stringNS;
}
......
......@@ -407,8 +407,6 @@ public:
~ObjCCallbackFunctionImpl()
{
if (m_type != CallbackInstanceMethod)
[[m_invocation.get() target] release];
[m_instanceClass release];
}
......@@ -609,7 +607,10 @@ JSObjectRef objCCallbackFunctionForBlock(JSContext *context, id target)
return 0;
const char* signature = _Block_signature(target);
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:signature]];
[invocation setTarget:[target copy]];
[invocation retainArguments];
id targetCopy = [target copy];
[invocation setTarget:targetCopy];
[targetCopy release];
return objCCallbackFunctionForInvocation(context, invocation, CallbackBlock, nil, signature);
}
......
......@@ -105,6 +105,7 @@ static char* createStringWithContentsOfFile(const char* fileName)
FILE* f = fopen(fileName, "r");
if (!f) {
fprintf(stderr, "Could not open file: %s\n", fileName);
free(buffer);
return 0;
}
......
......@@ -1996,6 +1996,7 @@ static char* createStringWithContentsOfFile(const char* fileName)
FILE* f = fopen(fileName, "r");
if (!f) {
fprintf(stderr, "Could not open file: %s\n", fileName);
free(buffer);
return 0;
}
......
2013-08-23 Andy Estes <aestes@apple.com>
Fix issues found by the Clang Static Analyzer
https://bugs.webkit.org/show_bug.cgi?id=120230
Reviewed by Darin Adler.
* API/JSValue.mm:
(valueToString): Don't leak every CFStringRef when in Objective-C GC.
* API/ObjCCallbackFunction.mm:
(JSC::ObjCCallbackFunctionImpl::~ObjCCallbackFunctionImpl): Don't
release m_invocation's target since NSInvocation will do it for us on
-dealloc.
(objCCallbackFunctionForBlock): Tell NSInvocation to retain its target
and -release our reference to the copied block.
* API/tests/minidom.c:
(createStringWithContentsOfFile): Free buffer before returning.
* API/tests/testapi.c:
(createStringWithContentsOfFile): Ditto.
2013-08-26 Brent Fulgham <bfulgham@apple.com>
[Windows] Unreviewed build fix after r154629.
......
2013-08-23 Andy Estes <aestes@apple.com>
Fix issues found by the Clang Static Analyzer
https://bugs.webkit.org/show_bug.cgi?id=120230
Reviewed by Darin Adler.
* wtf/ObjcRuntimeExtras.h:
(HardAutorelease): Added a canonical implementation of HardAutorelease.
2013-08-26 Zan Dobersek <zdobersek@igalia.com>
Undefine __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS before redefining them
......
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
* Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -27,16 +27,35 @@
#include <objc/message.h>
#ifdef __cplusplus
template<typename RetType, typename... ArgTypes>
RetType wtfObjcMsgSend(id target, SEL selector, ArgTypes... args)
inline RetType wtfObjcMsgSend(id target, SEL selector, ArgTypes... args)
{
return reinterpret_cast<RetType (*)(id, SEL, ArgTypes...)>(objc_msgSend)(target, selector, args...);
}
template<typename RetType, typename... ArgTypes>
RetType wtfCallIMP(IMP implementation, id target, SEL selector, ArgTypes... args)
inline RetType wtfCallIMP(IMP implementation, id target, SEL selector, ArgTypes... args)
{
return reinterpret_cast<RetType (*)(id, SEL, ArgTypes...)>(implementation)(target, selector, args...);
}
#endif // __cplusplus
#ifdef __OBJC__
// Use HardAutorelease to return an object made by a Core Foundation
// "create" or "copy" function as an autoreleased and garbage collected
// object. CF objects need to be "made collectable" for autorelease to work
// properly under GC.
inline id HardAutorelease(CFTypeRef object)
{
#ifndef OBJC_NO_GC
if (object)
CFMakeCollectable(object);
#elif !__has_feature(objc_arc)
[(id)object autorelease];
#endif
return (id)object;
}
#endif // __OBJC__
#endif // WTF_ObjcRuntimeExtras_h
2013-08-23 Andy Estes <aestes@apple.com>
Fix issues found by the Clang Static Analyzer
https://bugs.webkit.org/show_bug.cgi?id=120230
Reviewed by Darin Adler.
* WebCore.xcodeproj/project.pbxproj: Removed FoundationExtras.h.
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm: Removed CFAutoreleaseHelper().
(AXTextMarkerRange): Used HardAutorelease() instead of
CFAutoreleaseHelper().
(AXTextMarkerRangeStart): Ditto.
(AXTextMarkerRangeEnd): Ditto.
(textMarkerForVisiblePosition): Ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(-[WebCoreAVFMovieObserver initWithCallback:]): Called [super init]
first so that we don't later use ivars from the wrong self.
(-[WebCoreAVFLoaderDelegate initWithCallback:]): Ditto.
* platform/mac/FoundationExtras.h: Removed.
* platform/mac/KURLMac.mm:
(WebCore::KURL::operator NSURL *): Used WTF's HardAutorelease().
* platform/mac/WebCoreNSURLExtras.mm:
(WebCore::mapHostNameWithRange): Used HardAutorelease() instead of
WebCoreCFAutorelease().
(WebCore::URLWithData): Ditto.
(WebCore::userVisibleString): Ditto.
(WebCore::URLByRemovingComponentAndSubsequentCharacter): Used Vector<>
with an inline capacity rather than heap-allocating a buffer.
* platform/mac/WebCoreObjCExtras.h: Used HardAutorelease() instead of
WebCoreCFAutorelease().
* platform/text/mac/StringImplMac.mm:
(WTF::StringImpl::operator NSString *): Used WTF's HardAutorelease().
2013-08-26 Pratik Solanki <psolanki@apple.com>
Page::console() should return a reference
......@@ -2812,7 +2812,6 @@
935C476809AC4D4300A6AAB4 /* PlatformKeyboardEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 935C476609AC4D4300A6AAB4 /* PlatformKeyboardEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
935C476909AC4D4300A6AAB4 /* PlatformMouseEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 935C476709AC4D4300A6AAB4 /* PlatformMouseEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
935C476B09AC4D4F00A6AAB4 /* PlatformWheelEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 935C476A09AC4D4F00A6AAB4 /* PlatformWheelEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
935C476D09AC4D6300A6AAB4 /* FoundationExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 935C476C09AC4D6300A6AAB4 /* FoundationExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
935C477009AC4D7300A6AAB4 /* KeyEventMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 935C476E09AC4D7300A6AAB4 /* KeyEventMac.mm */; };
935C477509AC4D8E00A6AAB4 /* GapRects.h in Headers */ = {isa = PBXBuildFile; fileRef = 935C477409AC4D8D00A6AAB4 /* GapRects.h */; settings = {ATTRIBUTES = (Private, ); }; };
935F45420F7C3B5F00D7C1FB /* JSLazyEventListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 935F45400F7C3B5F00D7C1FB /* JSLazyEventListener.cpp */; };
......@@ -8104,7 +8103,7 @@
658436850AE01B7400E53753 /* FrameLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoadRequest.h; sourceTree = "<group>"; };
6593923509AE4346002C531F /* KURL.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURL.cpp; sourceTree = "<group>"; };
6593923609AE4346002C531F /* KURL.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = KURL.h; sourceTree = "<group>"; };
6593923909AE435C002C531F /* KURLMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = KURLMac.mm; sourceTree = "<group>"; };
6593923909AE435C002C531F /* KURLMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = KURLMac.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
659A7D120B6DB4D9001155B3 /* SubstituteData.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SubstituteData.h; sourceTree = "<group>"; };
659DDC8009E198BA001BF3C6 /* JSDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocument.cpp; sourceTree = "<group>"; };
659DDC8109E198BA001BF3C6 /* JSDocument.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSDocument.h; sourceTree = "<group>"; };
......@@ -9198,7 +9197,6 @@
935C476609AC4D4300A6AAB4 /* PlatformKeyboardEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformKeyboardEvent.h; sourceTree = "<group>"; };
935C476709AC4D4300A6AAB4 /* PlatformMouseEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformMouseEvent.h; sourceTree = "<group>"; };
935C476A09AC4D4F00A6AAB4 /* PlatformWheelEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformWheelEvent.h; sourceTree = "<group>"; };
935C476C09AC4D6300A6AAB4 /* FoundationExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FoundationExtras.h; sourceTree = "<group>"; };
935C476E09AC4D7300A6AAB4 /* KeyEventMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyEventMac.mm; sourceTree = "<group>"; };
935C477409AC4D8D00A6AAB4 /* GapRects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GapRects.h; sourceTree = "<group>"; };
935F45400F7C3B5F00D7C1FB /* JSLazyEventListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSLazyEventListener.cpp; sourceTree = "<group>"; };
......@@ -10314,7 +10312,7 @@
AA4739CF1757AFEC00E76767 /* UIRequestEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UIRequestEvent.cpp; path = Modules/indieui/UIRequestEvent.cpp; sourceTree = "<group>"; };
AA4739D01757AFEC00E76767 /* UIRequestEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIRequestEvent.h; path = Modules/indieui/UIRequestEvent.h; sourceTree = "<group>"; };
AA478A7D16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAccessibilityObjectWrapperMac.h; sourceTree = "<group>"; };
AA478A7E16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebAccessibilityObjectWrapperMac.mm; sourceTree = "<group>"; };
AA478A7E16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; lineEnding = 0; path = WebAccessibilityObjectWrapperMac.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
AA4C3A740B2B1679002334A2 /* InlineStyleSheetOwner.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InlineStyleSheetOwner.cpp; sourceTree = "<group>"; };
AA4C3A750B2B1679002334A2 /* InlineStyleSheetOwner.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InlineStyleSheetOwner.h; sourceTree = "<group>"; };
AA5F3B9016CC5BEB00455EB0 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
......@@ -10852,7 +10850,7 @@
B2AFFC850D00A5DF0030074D /* character-sets.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = "character-sets.txt"; sourceTree = "<group>"; };
B2AFFC860D00A5DF0030074D /* mac-encodings.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = "mac-encodings.txt"; sourceTree = "<group>"; };
B2AFFC870D00A5DF0030074D /* make-charset-table.pl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.script.perl; path = "make-charset-table.pl"; sourceTree = "<group>"; };
B2AFFC8A0D00A5DF0030074D /* StringImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = StringImplMac.mm; sourceTree = "<group>"; };
B2AFFC8A0D00A5DF0030074D /* StringImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = StringImplMac.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
B2AFFC8B0D00A5DF0030074D /* StringMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = StringMac.mm; sourceTree = "<group>"; };
B2AFFC8C0D00A5DF0030074D /* TextBoundaries.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = TextBoundaries.mm; sourceTree = "<group>"; };
B2AFFC8D0D00A5DF0030074D /* TextBreakIteratorInternalICUMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = TextBreakIteratorInternalICUMac.mm; sourceTree = "<group>"; };
......@@ -14534,7 +14532,6 @@
E1BA66F01742BD8600C20251 /* DynamicLinkerInterposing.h */,
1CA19E030DC255950065A994 /* EventLoopMac.mm */,
514B3F750C722055000530DF /* FileSystemMac.mm */,
935C476C09AC4D6300A6AAB4 /* FoundationExtras.h */,
C5392D331326AD0100043D35 /* HTMLConverter.h */,
C5392D341326AD0100043D35 /* HTMLConverter.mm */,
935C476E09AC4D7300A6AAB4 /* KeyEventMac.mm */,
......@@ -21817,7 +21814,6 @@
514C764E0CE9234E007EF3CD /* FormDataStreamMac.h in Headers */,
656D373A0ADBA5DE00A4554D /* FormState.h in Headers */,
41885B9311B6FDA6003383BB /* FormSubmission.h in Headers */,
935C476D09AC4D6300A6AAB4 /* FoundationExtras.h in Headers */,
A853123D11D0471B00D4D077 /* FragmentScriptingPermission.h in Headers */,
65BF022F0974816300C43196 /* Frame.h in Headers */,
A7B070D3130A409C00A3763C /* FrameActionScheduler.h in Headers */,
......@@ -73,6 +73,7 @@
#import "WebCoreObjCExtras.h"
#import "WebCoreSystemInterface.h"
#import "htmlediting.h"
#import <wtf/ObjcRuntimeExtras.h>
using namespace WebCore;
using namespace HTMLNames;
......@@ -403,14 +404,6 @@ using namespace std;
#pragma mark SystemInterface wrappers
static inline id CFAutoreleaseHelper(CFTypeRef obj)
{
if (obj)
CFMakeCollectable(obj);
[(id)obj autorelease];
return (id)obj;
}
static inline BOOL AXObjectIsTextMarker(id obj)
{
return obj != nil && CFGetTypeID(obj) == wkGetAXTextMarkerTypeID();
......@@ -427,21 +420,21 @@ static id AXTextMarkerRange(id startMarker, id endMarker)
ASSERT(endMarker != nil);
ASSERT(CFGetTypeID(startMarker) == wkGetAXTextMarkerTypeID());
ASSERT(CFGetTypeID(endMarker) == wkGetAXTextMarkerTypeID());
return CFAutoreleaseHelper(wkCreateAXTextMarkerRange((CFTypeRef)startMarker, (CFTypeRef)endMarker));
return HardAutorelease(wkCreateAXTextMarkerRange((CFTypeRef)startMarker, (CFTypeRef)endMarker));
}
static id AXTextMarkerRangeStart(id range)
{
ASSERT(range != nil);
ASSERT(CFGetTypeID(range) == wkGetAXTextMarkerRangeTypeID());
return CFAutoreleaseHelper(wkCopyAXTextMarkerRangeStart(range));
return HardAutorelease(wkCopyAXTextMarkerRangeStart(range));
}
static id AXTextMarkerRangeEnd(id range)
{
ASSERT(range != nil);
ASSERT(CFGetTypeID(range) == wkGetAXTextMarkerRangeTypeID());
return CFAutoreleaseHelper(wkCopyAXTextMarkerRangeEnd(range));
return HardAutorelease(wkCopyAXTextMarkerRangeEnd(range));
}
#pragma mark Search helpers
......@@ -526,7 +519,7 @@ static id textMarkerForVisiblePosition(AXObjectCache* cache, const VisiblePositi
if (!textMarkerData.axID)
return nil;
return CFAutoreleaseHelper(wkCreateAXTextMarker(&textMarkerData, sizeof(textMarkerData)));
return HardAutorelease(wkCreateAXTextMarker(&textMarkerData, sizeof(textMarkerData)));
}
- (id)textMarkerForVisiblePosition:(const VisiblePosition &)visiblePos
......
......@@ -1564,8 +1564,11 @@ NSArray* itemKVOProperties()
- (id)initWithCallback:(MediaPlayerPrivateAVFoundationObjC*)callback
{
self = [super init];
if (!self)
return nil;
m_callback = callback;
return [super init];
return self;
}
- (void)disconnect
......@@ -1688,8 +1691,11 @@ NSArray* itemKVOProperties()
- (id)initWithCallback:(MediaPlayerPrivateAVFoundationObjC*)callback
{
self = [super init];
if (!self)
return nil;
m_callback = callback;
return [super init];
return self;
}
- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
......
/*
* Copyright (C) 2004 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <CoreFoundation/CFBase.h>
#import <Foundation/NSObject.h>
// Use HardAutorelease to return an object made by a CoreFoundation
// "create" or "copy" function as an autoreleased and garbage collected
// object. CF objects need to be "made collectable" for autorelease to work
// properly under GC.
static inline id HardAutorelease(CFTypeRef object)
{
if (object)
CFMakeCollectable(object);
[(id)object autorelease];
return (id)object;
}
......@@ -27,7 +27,7 @@
#import "KURL.h"
#import "CFURLExtras.h"
#import "FoundationExtras.h"
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/text/CString.h>
namespace WebCore {
......
......@@ -31,6 +31,7 @@
#import "WebCoreNSStringExtras.h"
#import "WebCoreNSURLExtras.h"
#import "WebCoreSystemInterface.h"
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/RetainPtr.h>
#import <wtf/Vector.h>
#import <unicode/uchar.h>
......@@ -247,7 +248,7 @@ static NSString *mapHostNameWithRange(NSString *string, NSRange range, BOOL enco
if (encode && [string rangeOfString:@"%" options:NSLiteralSearch range:range].location != NSNotFound) {
NSString *substring = [string substringWithRange:range];
substring = WebCoreCFAutorelease(CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef)substring, CFSTR("")));
substring = HardAutorelease(CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef)substring, CFSTR("")));
if (substring) {
string = substring;
range = NSMakeRange(0, [string length]);
......@@ -563,9 +564,9 @@ NSURL *URLWithData(NSData *data, NSURL *baseURL)
// (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
// could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back
// onto using ISO Latin 1 in those cases.
result = WebCoreCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
result = HardAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
if (!result)
result = WebCoreCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
result = HardAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
} else
result = [NSURL URLWithString:@""];
......@@ -682,16 +683,15 @@ static NSURL *URLByRemovingComponentAndSubsequentCharacter(NSURL *URL, CFURLComp
// Remove one subsequent character.
range.length++;
UInt8* urlBytes;
UInt8 buffer[2048];
CFIndex numBytes = CFURLGetBytes((CFURLRef)URL, buffer, 2048);
Vector<UInt8, 2048> buffer(2048);
CFIndex numBytes = CFURLGetBytes((CFURLRef)URL, buffer.data(), 2048);
if (numBytes == -1) {
numBytes = CFURLGetBytes((CFURLRef)URL, NULL, 0);
urlBytes = static_cast<UInt8*>(malloc(numBytes));
CFURLGetBytes((CFURLRef)URL, urlBytes, numBytes);
} else
urlBytes = buffer;
buffer.grow(numBytes);
CFURLGetBytes((CFURLRef)URL, buffer.data(), numBytes);
}
UInt8* urlBytes = buffer.data();
if (numBytes < range.location)
return URL;
......@@ -703,9 +703,6 @@ static NSURL *URLByRemovingComponentAndSubsequentCharacter(NSURL *URL, CFURLComp
NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingUTF8, NULL));
if (!result)
result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingISOLatin1, NULL));
if (urlBytes != buffer)
free(urlBytes);
return result ? [result autorelease] : URL;
}
......@@ -841,7 +838,7 @@ NSString *userVisibleString(NSURL *URL)
result = mapHostNames(result, !needsHostNameDecoding);
result = [result precomposedStringWithCanonicalMapping];
return WebCoreCFAutorelease(createStringWithEscapedUnsafeCharacters((CFStringRef)result));
return HardAutorelease(createStringWithEscapedUnsafeCharacters((CFStringRef)result));
}
BOOL isUserVisibleURL(NSString *string)
......
......@@ -33,18 +33,6 @@
extern "C" {
#endif
// Use WebCFAutorelease to return an object made by a CoreFoundation
// "create" or "copy" function as an autoreleased and garbage collected
// object. CF objects need to be "made collectable" for autorelease to work
// properly under GC.
static inline id WebCoreCFAutorelease(CFTypeRef obj)
{
if (obj)
CFMakeCollectable(obj);
[(id)obj autorelease];
return (id)obj;
}
void WebCoreObjCFinalizeOnMainThread(Class cls);
// The 'Class' that should be passed in here is the class of the
......
......@@ -18,11 +18,11 @@
*
*/
#include "config.h"
#include <wtf/text/StringImpl.h>
#import "config.h"
#import <wtf/text/StringImpl.h>
#include "FoundationExtras.h"
#include <wtf/RetainPtr.h>
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/RetainPtr.h>
namespace WTF {
......
2013-08-23 Andy Estes <aestes@apple.com>
Fix issues found by the Clang Static Analyzer
https://bugs.webkit.org/show_bug.cgi?id=120230
Reviewed by Darin Adler.
* Misc/WebNSFileManagerExtras.mm:
(-[NSFileManager _webkit_startupVolumeName]): Used HardAutorelease()
instead of WebCFAutorelease().
* Misc/WebNSObjectExtras.h: Removed definition of WebCFAutorelease().
* Misc/WebNSURLExtras.mm:
(-[NSURL _web_URLWithLowercasedScheme]): Used HardAutorelease()
instead of WebCFAutorelease().
* Plugins/Hosted/WebHostedNetscapePluginView.mm:
(-[WebHostedNetscapePluginView createPluginLayer]): Stop leaking
CGColors (CALayer retains its backgroundColor property despite the
property attributes claiming otherwise).
* Plugins/WebBasePluginPackage.mm:
(+[WebBasePluginPackage preferredLocalizationName]): Used
HardAutorelease() instead of WebCFAutorelease().
* WebView/WebDeviceOrientationProviderMock.mm:
(-[WebDeviceOrientationProviderMockInternal lastOrientation]): Stop
leaking WebDeviceOrientations.
* WebView/WebPDFRepresentation.mm:
(-[WebPDFRepresentation convertPostScriptDataSourceToPDF:]): Used
HardAutorelease() instead of WebCFAutorelease().
* WebView/WebView.mm:
(+[WebView _setCacheModel:]): Ditto.
(-[WebView _removeObjectForIdentifier:]): Ditto.
2013-08-26 Alexey Proskuryakov <ap@apple.com>
[Mac] can-read-in-dragstart-event.html and can-read-in-copy-and-cut-events.html fail
......
......@@ -29,11 +29,11 @@
#import <WebKit/WebNSFileManagerExtras.h>
#import "WebKitNSStringExtras.h"
#import "WebNSObjectExtras.h"
#import "WebNSURLExtras.h"
#import <wtf/Assertions.h>
#import <WebKitSystemInterface.h>
#import <sys/stat.h>
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/RetainPtr.h>
@implementation NSFileManager (WebNSFileManagerExtras)
......@@ -98,7 +98,7 @@ static void *setMetaData(void* context)
RetainPtr<DADiskRef> disk = adoptCF(DADiskCreateFromVolumePath(kCFAllocatorDefault, session.get(), (CFURLRef)[NSURL fileURLWithPath:@"/"]));
RetainPtr<CFDictionaryRef> diskDescription = adoptCF(DADiskCopyDescription(disk.get()));
RetainPtr<NSString> diskName = (NSString *)CFDictionaryGetValue(diskDescription.get(), kDADiskDescriptionVolumeNameKey);
return WebCFAutorelease(diskName.leakRef());
return HardAutorelease(diskName.leakRef());
}
// -[NSFileManager fileExistsAtPath:] returns NO if there is a broken symlink at the path.
......
......@@ -30,18 +30,6 @@
#import <objc/objc-class.h>
#import <objc/objc.h>
// Use WebCFAutorelease to return an object made by a CoreFoundation
// "create" or "copy" function as an autoreleased and garbage collected
// object. CF objects need to be "made collectable" for autorelease to work
// properly under GC.
static inline id WebCFAutorelease(CFTypeRef obj)
{
if (obj)
CFMakeCollectable(obj);
[(id)obj autorelease];
return (id)obj;
}
@interface NSObject (WebNSObjectExtras)
+ (id)_webkit_invokeOnMainThread;
- (id)_webkit_invokeOnMainThread;
......
......@@ -32,7 +32,6 @@
#import "WebKitNSStringExtras.h"
#import "WebLocalizableStrings.h"
#import "WebNSDataExtras.h"
#import "WebNSObjectExtras.h"
#import "WebSystemInterface.h"
#import <Foundation/NSURLRequest.h>
#import <WebCore/KURL.h>
......@@ -40,6 +39,7 @@
#import <WebCore/WebCoreNSURLExtras.h>
#import <WebKitSystemInterface.h>
#import <wtf/Assertions.h>
#import <wtf/ObjcRuntimeExtras.h>
#import <unicode/uchar.h>
#import <unicode/uscript.h>
......@@ -214,7 +214,7 @@ using namespace WTF;
}
NSURL *result = changed
? (NSURL *)WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, buffer, bytesFilled, kCFStringEncodingUTF8, nil, YES))
? (NSURL *)HardAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, buffer, bytesFilled, kCFStringEncodingUTF8, nil, YES))
: (NSURL *)self;
if (buffer != static_buffer) {
......
......@@ -51,6 +51,7 @@
#import <runtime/InitializeThreading.h>
#import <wtf/Assertions.h>
#import <wtf/MainThread.h>
#import <wtf/ObjcRuntimeExtras.h>
using namespace WebCore;
using namespace WebKit;
......@@ -164,7 +165,7 @@ extern "C" {
_pluginLayer.get().bounds = realPluginLayer.get().bounds;
_pluginLayer.get().geometryFlipped = YES;
_pluginLayer.get().backgroundColor = CGColorCreateGenericRGB(1, 0, 1, 1);
_pluginLayer.get().backgroundColor = adoptCF(CGColorCreateGenericRGB(1, 0, 1, 1)).get();
realPluginLayer.get().autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
[_pluginLayer.get() addSublayer:realPluginLayer.get()];
......
......@@ -32,12 +32,12 @@
#import <WebCore/RunLoop.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <WebKit/WebKitNSStringExtras.h>
#import <WebKit/WebNSObjectExtras.h>
#import <WebKit/WebNetscapePluginPackage.h>
#import <WebKit/WebPluginPackage.h>
#import <runtime/InitializeThreading.h>
#import <wtf/Assertions.h>
#import <wtf/MainThread.h>
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/Vector.h>
#import <wtf/text/CString.h>
......@@ -90,7 +90,7 @@ using namespace WebCore;
+ (NSString *)preferredLocalizationName
{
return WebCFAutorelease(WKCopyCFLocalizationPreferredName(NULL));
return HardAutorelease(WKCopyCFLocalizationPreferredName(NULL));
}
#if COMPILER(CLANG)
......