Bug 1710867 - P1: Add returned containers to autorelease pool. r=morgan

When we return a container, like an NSArray of MOXAccessible children the container needs
to be added to the autorelease pool so that it is released and so are its members.

Differential Revision: https://phabricator.services.mozilla.com/D115273
This commit is contained in:
Eitan Isaacson 2021-05-17 22:35:39 +00:00
parent f1b447b280
commit 9293cb7fee
6 changed files with 26 additions and 20 deletions

View File

@ -95,7 +95,8 @@ mozilla::LogModule* GetMacAccessibilityLog() {
}
NSMutableArray* attributes =
attributesForEachClass [[self class]] ?: [[NSMutableArray alloc] init];
attributesForEachClass [[self class]]
?: [[[NSMutableArray alloc] init] autorelease];
NSDictionary* getters = mac::AttributeGetters();
if (![attributes count]) {
@ -162,7 +163,8 @@ mozilla::LogModule* GetMacAccessibilityLog() {
// If this is an array of mozAccessibles, get each element's represented
// view and remove it from the returned array if it should be ignored.
NSUInteger arrSize = [value count];
NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity:arrSize];
NSMutableArray* arr =
[[[NSMutableArray alloc] initWithCapacity:arrSize] autorelease];
for (NSUInteger i = 0; i < arrSize; i++) {
id<mozAccessible> mozAcc = GetObjectOrRepresentedView(value[i]);
if ([mozAcc isAccessibilityElement]) {
@ -259,7 +261,7 @@ mozilla::LogModule* GetMacAccessibilityLog() {
return nil;
}
NSMutableArray* actionNames = [[NSMutableArray alloc] init];
NSMutableArray* actionNames = [[[NSMutableArray alloc] init] autorelease];
NSDictionary* actions = mac::Actions();
for (NSString* action in actions) {
@ -309,7 +311,7 @@ mozilla::LogModule* GetMacAccessibilityLog() {
return nil;
}
NSMutableArray* attributeNames = [[NSMutableArray alloc] init];
NSMutableArray* attributeNames = [[[NSMutableArray alloc] init] autorelease];
NSDictionary* attributes = mac::ParameterizedAttributeGetters();
for (NSString* attribute in attributes) {
@ -467,7 +469,8 @@ mozilla::LogModule* GetMacAccessibilityLog() {
}
- (NSArray*)moxUnignoredChildren {
NSMutableArray* unignoredChildren = [[NSMutableArray alloc] init];
NSMutableArray* unignoredChildren =
[[[NSMutableArray alloc] init] autorelease];
NSArray* allChildren = [self moxChildren];
for (MOXAccessibleBase* nativeChild in allChildren) {

View File

@ -80,7 +80,8 @@ using namespace mozilla::a11y;
// don't come up short on the final result count.
int resultLimit = [self shouldApplyPostFilter] ? -1 : mResultLimit;
NSMutableArray<mozAccessible*>* matches = [[NSMutableArray alloc] init];
NSMutableArray<mozAccessible*>* matches =
[[[NSMutableArray alloc] init] autorelease];
AccessibleOrProxy geckoRootAcc = [self rootGeckoAccessible];
AccessibleOrProxy geckoStartAcc = [self startGeckoAccessible];
Pivot p = Pivot(geckoRootAcc);
@ -130,7 +131,8 @@ using namespace mozilla::a11y;
return matches;
}
NSMutableArray<mozAccessible*>* postMatches = [[NSMutableArray alloc] init];
NSMutableArray<mozAccessible*>* postMatches =
[[[NSMutableArray alloc] init] autorelease];
nsString searchText;
nsCocoaUtils::GetStringForNSString(mSearchText, searchText);
@ -225,7 +227,7 @@ using namespace mozilla::a11y;
- (NSArray*)performSearch {
AccessibleOrProxy geckoRootAcc = [self rootGeckoAccessible];
AccessibleOrProxy geckoStartAcc = [self startGeckoAccessible];
NSMutableArray* matches = [[NSMutableArray alloc] init];
NSMutableArray* matches = [[[NSMutableArray alloc] init] autorelease];
for (id key in mSearchKeys) {
if ([key isEqualToString:@"AXAnyTypeSearchKey"]) {
RotorRule rule =

View File

@ -90,11 +90,11 @@ static nsTHashMap<nsUint64HashKey, MOXTextMarkerDelegate*> sDelegates;
// This is the base info object, includes the selected marker range and
// the change type depending on the collapsed state of the selection.
NSMutableDictionary* info = [@{
NSMutableDictionary* info = [[@{
@"AXSelectedTextMarkerRange" : selectedGeckoRange.IsValid() ? mSelection
: [NSNull null],
@"AXTextStateChangeType" : @(stateChangeType),
} mutableCopy];
} mutableCopy] autorelease];
GeckoTextMarker caretMarker(mGeckoDocAccessible, mCaret);
GeckoTextMarker prevCaretMarker(mGeckoDocAccessible, mPrevCaret);

View File

@ -18,7 +18,7 @@ namespace utils {
// convert an array of Gecko accessibles to an NSArray of native accessibles
NSArray<mozAccessible*>* ConvertToNSArray(nsTArray<LocalAccessible*>& aArray) {
NSMutableArray* nativeArray = [[NSMutableArray alloc] init];
NSMutableArray* nativeArray = [[[NSMutableArray alloc] init] autorelease];
// iterate through the list, and get each native accessible.
size_t totalCount = aArray.Length();
@ -35,7 +35,7 @@ NSArray<mozAccessible*>* ConvertToNSArray(nsTArray<LocalAccessible*>& aArray) {
// convert an array of Gecko proxy accessibles to an NSArray of native
// accessibles
NSArray<mozAccessible*>* ConvertToNSArray(nsTArray<RemoteAccessible*>& aArray) {
NSMutableArray* nativeArray = [[NSMutableArray alloc] init];
NSMutableArray* nativeArray = [[[NSMutableArray alloc] init] autorelease];
// iterate through the list, and get each native accessible.
size_t totalCount = aArray.Length();

View File

@ -336,8 +336,8 @@ static const uint64_t kCacheInitialized = ((uint64_t)0x1) << 63;
- (NSArray*)moxChildren {
MOZ_ASSERT(!mGeckoAccessible.IsNull());
NSMutableArray* children =
[[NSMutableArray alloc] initWithCapacity:mGeckoAccessible.ChildCount()];
NSMutableArray* children = [[[NSMutableArray alloc]
initWithCapacity:mGeckoAccessible.ChildCount()] autorelease];
for (uint32_t childIdx = 0; childIdx < mGeckoAccessible.ChildCount();
childIdx++) {
@ -972,7 +972,8 @@ struct RoleDescrComparator {
- (NSArray<mozAccessible*>*)getRelationsByType:(RelationType)relationType {
if (LocalAccessible* acc = mGeckoAccessible.AsAccessible()) {
NSMutableArray<mozAccessible*>* relations = [[NSMutableArray alloc] init];
NSMutableArray<mozAccessible*>* relations =
[[[NSMutableArray alloc] init] autorelease];
Relation rel = acc->RelationByType(relationType);
while (LocalAccessible* relAcc = rel.Next()) {
if (mozAccessible* relNative = GetNativeFromGeckoAccessible(relAcc)) {
@ -1023,7 +1024,7 @@ struct RoleDescrComparator {
MOXTextMarkerDelegate* delegate =
static_cast<MOXTextMarkerDelegate*>([self moxTextMarkerDelegate]);
NSMutableDictionary* userInfo =
[[delegate selectionChangeInfo] mutableCopy];
[[[delegate selectionChangeInfo] mutableCopy] autorelease];
userInfo[@"AXTextChangeElement"] = self;
mozAccessible* webArea = [self topWebArea];

View File

@ -301,7 +301,7 @@ enum CachedBool { eCachedBoolMiss, eCachedTrue, eCachedFalse };
}
NSMutableArray* colHeaders =
[[NSMutableArray alloc] initWithCapacity:numCols];
[[[NSMutableArray alloc] initWithCapacity:numCols] autorelease];
for (uint32_t i = 0; i < numCols; i++) {
AccessibleOrProxy cell;
@ -450,7 +450,7 @@ enum CachedBool { eCachedBoolMiss, eCachedTrue, eCachedFalse };
// use pivot here to do a deep traversal of all rows nested
// in this outline, not just those which are direct
// children, since that's what VO expects.
NSMutableArray* allRows = [[NSMutableArray alloc] init];
NSMutableArray* allRows = [[[NSMutableArray alloc] init] autorelease];
Pivot p = Pivot(mGeckoAccessible);
OutlineRule rule = OutlineRule();
AccessibleOrProxy firstChild = mGeckoAccessible.FirstChild();
@ -466,7 +466,7 @@ enum CachedBool { eCachedBoolMiss, eCachedTrue, eCachedFalse };
if (LocalAccessible* acc = mGeckoAccessible.AsAccessible()) {
if (acc->IsContent() && acc->GetContent()->IsXULElement(nsGkAtoms::tree)) {
XULTreeAccessible* treeAcc = (XULTreeAccessible*)acc;
NSMutableArray* cols = [[NSMutableArray alloc] init];
NSMutableArray* cols = [[[NSMutableArray alloc] init] autorelease];
// XUL trees store their columns in a group at the tree's first
// child. Here, we iterate over that group to get each column's
// native accessible and add it to our col array.
@ -487,7 +487,7 @@ enum CachedBool { eCachedBoolMiss, eCachedTrue, eCachedFalse };
}
- (NSArray*)moxSelectedRows {
NSMutableArray* selectedRows = [[NSMutableArray alloc] init];
NSMutableArray* selectedRows = [[[NSMutableArray alloc] init] autorelease];
NSArray* allRows = [self moxRows];
for (mozAccessible* row in allRows) {
if ([row stateWithMask:states::SELECTED] != 0) {