Bug 1418448 part 1: Accessible HandlerProvider: Clean up DynamicIA2Data correctly. r=aklotz
authorJames Teh <jteh@mozilla.com>
Fri, 24 Nov 2017 15:12:37 +1000
changeset 394018 3f52f6885fc5c9422d402664965ff317069bf58f
parent 394017 0d51f408d0c543ab02f877ae999bfa9c77b1b9f4
child 394019 57aa3370993fb4f1fca77ebd535ae189abe75363
push id32989
push userdluca@mozilla.com
push dateWed, 29 Nov 2017 10:09:52 +0000
treeherdermozilla-central@40b464eb6b31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1418448
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1418448 part 1: Accessible HandlerProvider: Clean up DynamicIA2Data correctly. r=aklotz DynamicIA2Data contains several BSTRs that need to be freed with SysFreeString. Previously, we just did a ZeroMemory without actually freeing them. This cleanup code is placed in a header file so it can be used by AccessibleHandler as well. MozReview-Commit-ID: 4SWuK9oMRYZ
accessible/ipc/win/HandlerProvider.cpp
accessible/ipc/win/HandlerProvider.h
accessible/ipc/win/handler/HandlerDataCleanup.h
accessible/ipc/win/handler/moz.build
--- a/accessible/ipc/win/HandlerProvider.cpp
+++ b/accessible/ipc/win/HandlerProvider.cpp
@@ -12,16 +12,17 @@
 #include "AccessibleDocument.h"
 #include "AccessibleTable.h"
 #include "AccessibleTable2.h"
 #include "AccessibleTableCell.h"
 #include "HandlerData.h"
 #include "HandlerData_i.c"
 #include "mozilla/Assertions.h"
 #include "mozilla/a11y/AccessibleWrap.h"
+#include "mozilla/a11y/HandlerDataCleanup.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/Move.h"
 #include "mozilla/mscom/AgileReference.h"
 #include "mozilla/mscom/FastMarshaler.h"
 #include "mozilla/mscom/Interceptor.h"
 #include "mozilla/mscom/MainThreadHandoff.h"
 #include "mozilla/mscom/MainThreadInvoker.h"
 #include "mozilla/mscom/Ptr.h"
@@ -127,17 +128,18 @@ HandlerProvider::GetAndSerializePayload(
   // AddRef/Release pair for this reference is handled by payloadRef
   payload.mGeckoBackChannel = this;
 
   mSerializer = MakeUnique<mscom::StructToStream>(payload, &IA2Payload_Encode);
 
   // Now that we have serialized payload, we should clean up any
   // BSTRs, interfaces, etc. fetched in BuildInitialIA2Data.
   CleanupStaticIA2Data(payload.mStaticData);
-  CleanupDynamicIA2Data(payload.mDynamicData);
+  // No need to zero memory, since payload is going out of scope.
+  CleanupDynamicIA2Data(payload.mDynamicData, false);
 }
 
 HRESULT
 HandlerProvider::GetHandlerPayloadSize(NotNull<mscom::IInterceptor*> aInterceptor,
                                        NotNull<DWORD*> aOutPayloadSize)
 {
   MOZ_ASSERT(mscom::IsCurrentThreadMTA());
 
@@ -417,23 +419,16 @@ HandlerProvider::CleanupStaticIA2Data(St
   }
   if (aData.mIATableCell) {
     aData.mIATableCell->Release();
   }
   ZeroMemory(&aData, sizeof(StaticIA2Data));
 }
 
 void
-HandlerProvider::CleanupDynamicIA2Data(DynamicIA2Data& aData)
-{
-  ::VariantClear(&aData.mRole);
-  ZeroMemory(&aData, sizeof(DynamicIA2Data));
-}
-
-void
 HandlerProvider::BuildInitialIA2Data(
   NotNull<mscom::IInterceptor*> aInterceptor,
   StaticIA2Data* aOutStaticData,
   DynamicIA2Data* aOutDynamicData)
 {
   BuildStaticIA2Data(aInterceptor, aOutStaticData);
   if (!aOutStaticData->mIA2) {
     return;
--- a/accessible/ipc/win/HandlerProvider.h
+++ b/accessible/ipc/win/HandlerProvider.h
@@ -70,17 +70,16 @@ private:
                               NotNull<mscom::IInterceptor*> aInterceptor);
   void BuildStaticIA2Data(NotNull<mscom::IInterceptor*> aInterceptor,
                           StaticIA2Data* aOutData);
   void BuildDynamicIA2Data(DynamicIA2Data* aOutIA2Data);
   void BuildInitialIA2Data(NotNull<mscom::IInterceptor*> aInterceptor,
                            StaticIA2Data* aOutStaticData,
                            DynamicIA2Data* aOutDynamicData);
   static void CleanupStaticIA2Data(StaticIA2Data& aData);
-  static void CleanupDynamicIA2Data(DynamicIA2Data& aData);
   bool IsTargetInterfaceCacheable();
   // Replace a raw object from the main thread with a wrapped, intercepted
   // object suitable for calling from the MTA.
   // The reference to the original object is adopted; i.e. you should not
   // separately release it.
   // This is intended for objects returned from method calls on the main thread.
   template<typename Interface> HRESULT ToWrappedObject(Interface** aObj);
   void GetAllTextInfoMainThread(BSTR* aText,
new file mode 100644
--- /dev/null
+++ b/accessible/ipc/win/handler/HandlerDataCleanup.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HandlerDataCleanup_h
+#define mozilla_a11y_HandlerDataCleanup_h
+
+#include <OleAuto.h>
+#include "HandlerData.h"
+
+namespace mozilla {
+namespace a11y {
+
+inline void
+CleanupDynamicIA2Data(DynamicIA2Data& aData, bool aZero=true)
+{
+  ::VariantClear(&aData.mRole);
+  if (aData.mKeyboardShortcut) {
+    ::SysFreeString(aData.mKeyboardShortcut);
+  }
+  if (aData.mName) {
+    ::SysFreeString(aData.mName);
+  }
+  if (aData.mDescription) {
+    ::SysFreeString(aData.mDescription);
+  }
+  if (aData.mDefaultAction) {
+    ::SysFreeString(aData.mDefaultAction);
+  }
+  if (aData.mValue) {
+    ::SysFreeString(aData.mValue);
+  }
+  if (aData.mAttributes) {
+    ::SysFreeString(aData.mAttributes);
+  }
+  if (aData.mIA2Locale.language)  {
+    ::SysFreeString(aData.mIA2Locale.language);
+  }
+  if (aData.mIA2Locale.country)  {
+    ::SysFreeString(aData.mIA2Locale.country);
+  }
+  if (aData.mIA2Locale.variant)  {
+    ::SysFreeString(aData.mIA2Locale.variant);
+  }
+  if (aZero) {
+    ZeroMemory(&aData, sizeof(DynamicIA2Data));
+  }
+}
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif // mozilla_a11y_HandlerDataCleanup_h
--- a/accessible/ipc/win/handler/moz.build
+++ b/accessible/ipc/win/handler/moz.build
@@ -1,17 +1,20 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SharedLibrary('AccessibleHandler')
 
-EXPORTS.mozilla.a11y += ['AccessibleHandler.h']
+EXPORTS.mozilla.a11y += [
+    'AccessibleHandler.h',
+    'HandlerDataCleanup.h',
+]
 
 LOCAL_INCLUDES += [
     '/accessible/interfaces/ia2',
     '/ipc/mscom/oop',
 ]
 
 SOURCES += [
     '!dlldata.c',