Add FX_STACK_ALLOCATED() to more fpdfapi classes.
Improve comment explaining FX_STACK_ALLOCATED rationale.
Change-Id: I8a2da5bb240cd7fbbee0517a40fbcc6068eb90b9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/89970
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h
index 32d8296..d2ff1ac 100644
--- a/core/fpdfapi/page/cpdf_page.h
+++ b/core/fpdfapi/page/cpdf_page.h
@@ -13,6 +13,7 @@
#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
#include "core/fpdfapi/page/ipdf_page.h"
#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/observed_ptr.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
@@ -43,6 +44,7 @@
class RenderContextClearer {
public:
+ FX_STACK_ALLOCATED();
explicit RenderContextClearer(CPDF_Page* pPage);
~RenderContextClearer();
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h
index 6761a97..2270c7d 100644
--- a/core/fpdfapi/parser/cpdf_array.h
+++ b/core/fpdfapi/parser/cpdf_array.h
@@ -162,6 +162,7 @@
class CPDF_ArrayLocker {
public:
+ FX_STACK_ALLOCATED();
using const_iterator = CPDF_Array::const_iterator;
explicit CPDF_ArrayLocker(const CPDF_Array* pArray);
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index d8ba1c0..d2f8143 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -137,6 +137,7 @@
class CPDF_DictionaryLocker {
public:
+ FX_STACK_ALLOCATED();
using const_iterator = CPDF_Dictionary::const_iterator;
explicit CPDF_DictionaryLocker(const CPDF_Dictionary* pDictionary);
diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h
index 8669123..d9bf9c9 100644
--- a/core/fxcrt/fx_memory.h
+++ b/core/fxcrt/fx_memory.h
@@ -89,7 +89,11 @@
} // namespace internal
} // namespace pdfium
-// Force stack allocation of a class.
+// Force stack allocation of a class. Classes that do complex work in a
+// destructor, such as the flushing of buffers, should be declared as
+// stack-allocated as possible, since future memory allocation schemes
+// may not run destructors in a predictable manner if an instance is
+// heap-allocated.
#define FX_STACK_ALLOCATED() \
void* operator new(size_t) = delete; \
void* operator new(size_t, void*) = delete