pdfium/testing/embedder_test_main.cpp
Lei Zhang 09166ad552 Reland "Stop trying to destroy PartitionAlloc"
This is a reland of commit f8e0f053178d9030b9e3878d780bc75f70518e1c
Avoid exit-time destructors this time.

Original change's description:
> Stop trying to destroy PartitionAlloc
>
> Attempting to destroy and reinitialize PartitionAlloc results in
> PartitionAlloc leaking address space. So destroying PartitionAlloc to
> "fix a memory leak" actually makes the situation worse in PA-enabled
> builds where PDFium gets repeatedly destroyed and reinitialized.
>
> Delete FX_InitializeMemoryAllocators() and FX_DestroyMemoryAllocators()
> and update their callers. Then make the PartitionAllocator instances
> initialized on first use again. This approximately reverts
> https://pdfium-review.googlesource.com/116751 without re-introducing
> NoDestructor usage.
>
> Change FPDFViewEmbedderTest.RepeatedInitDestroy to loop more than 4096
> times to show this works. While only changing the test, as seen in
> https://pdfium-review.googlesource.com/144731, results in
> pdfium_embeddertests crashes.
>
> Bug: 42270890
> Change-Id: I79f9c2fa5adf0e0f9c8b8bf30332c96966ed2c96
> Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/145070
> Commit-Queue: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Tom Sepez <tsepez@chromium.org>

Bug: 42270890
Change-Id: I53b91f6957783b33c1074b839d22b7922e4cfd5e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/145111
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
2026-03-19 11:20:36 -07:00

50 lines
1.5 KiB
C++

// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "build/build_config.h"
#include "testing/embedder_test_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#ifdef PDF_ENABLE_V8
#include "testing/v8_test_environment.h"
#endif // PDF_ENABLE_V8
#if defined(PDF_USE_PARTITION_ALLOC)
#include "testing/allocator_shim_config.h"
#endif
#if defined(BUILD_WITH_CHROMIUM) && defined(PDF_USE_SKIA)
#include "testing/chromium_support/discardable_memory_allocator.h" // nogncheck
#endif
// Can't use gtest-provided main since we need to create our own
// testing environment which needs the executable path in order to
// find the external V8 binary data files.
int main(int argc, char** argv) {
#if defined(PDF_USE_PARTITION_ALLOC)
pdfium::ConfigurePartitionAllocShimPartitionForTest();
#endif
#ifdef PDF_ENABLE_V8
// The env will be deleted by gtest.
AddGlobalTestEnvironment(new V8TestEnvironment(argv[0]));
#endif // PDF_ENABLE_V8
// The env will be deleted by gtest.
AddGlobalTestEnvironment(new EmbedderTestEnvironment);
testing::InitGoogleTest(&argc, argv);
testing::InitGoogleMock(&argc, argv);
// Anything remaining in argc/argv is an embedder_tests flag.
EmbedderTestEnvironment::GetInstance()->AddFlags(argc, argv);
#if defined(BUILD_WITH_CHROMIUM) && defined(PDF_USE_SKIA)
chromium_support::InitializeDiscardableMemoryAllocator();
#endif
return RUN_ALL_TESTS();
}