Skip to content

Commit 4fca259

Browse files
committed
bug 1240893 - ensure accessibles are shutdown before their document r=davidb, smaug
1 parent b7e4754 commit 4fca259

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

accessible/generic/Accessible.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ using namespace mozilla::a11y;
9393
////////////////////////////////////////////////////////////////////////////////
9494
// Accessible: nsISupports and cycle collection
9595

96-
NS_IMPL_CYCLE_COLLECTION(Accessible, mContent)
96+
NS_IMPL_CYCLE_COLLECTION_CLASS(Accessible)
97+
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Accessible)
98+
tmp->Shutdown();
99+
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
100+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Accessible)
101+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent, mDoc)
102+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
97103

98104
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Accessible)
99105
if (aIID.Equals(NS_GET_IID(Accessible)))

accessible/generic/Accessible.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ class Accessible : public nsISupports
11381138

11391139
// Data Members
11401140
nsCOMPtr<nsIContent> mContent;
1141-
DocAccessible* mDoc;
1141+
RefPtr<DocAccessible> mDoc;
11421142

11431143
Accessible* mParent;
11441144
nsTArray<Accessible*> mChildren;

accessible/generic/DocAccessible.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ static const uint32_t kRelationAttrsLen = ArrayLength(kRelationAttrs);
8080

8181
DocAccessible::
8282
DocAccessible(nsIDocument* aDocument, nsIPresShell* aPresShell) :
83-
HyperTextAccessibleWrap(nullptr, this),
83+
// XXX don't pass a document to the Accessible constructor so that we don't
84+
// set mDoc until our vtable is fully setup. If we set mDoc before setting
85+
// up the vtable we will call Accessible::AddRef() but not the overrides of
86+
// it for subclasses. It is important to call those overrides to avoid
87+
// confusing leak checking machinary.
88+
HyperTextAccessibleWrap(nullptr, nullptr),
8489
// XXX aaronl should we use an algorithm for the initial cache size?
8590
mAccessibleCache(kDefaultCacheLength),
8691
mNodeToAccessibleMap(kDefaultCacheLength),
@@ -92,6 +97,7 @@ DocAccessible::
9297
{
9398
mGenericTypes |= eDocument;
9499
mStateFlags |= eNotNodeMapEntry;
100+
mDoc = this;
95101

96102
MOZ_ASSERT(mPresShell, "should have been given a pres shell");
97103
mPresShell->SetDocAccessible(this);

accessible/windows/msaa/AccessibleWrap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ void
9090
AccessibleWrap::Shutdown()
9191
{
9292
if (mID != kNoID) {
93-
auto doc = static_cast<DocAccessibleWrap*>(mDoc);
93+
auto doc = static_cast<DocAccessibleWrap*>(mDoc.get());
9494
MOZ_ASSERT(doc);
9595
if (doc) {
9696
doc->RemoveID(mID);
97+
mID = kNoID;
9798
}
9899
}
99100

0 commit comments

Comments
 (0)