pdfium/testing/unit_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

44 lines
1.3 KiB
C++

// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/pdf_test_environment.h"
#if defined(PDF_USE_PARTITION_ALLOC)
#include "testing/allocator_shim_config.h"
#endif
#ifdef PDF_ENABLE_V8
#include "testing/v8_test_environment.h"
#ifdef PDF_ENABLE_XFA
#include "testing/xfa_test_environment.h"
#endif // PDF_ENABLE_XFA
#endif // PDF_ENABLE_V8
// Can't use gtest-provided main since we need to initialize partition
// alloc before invoking any test, and add test environments.
int main(int argc, char** argv) {
#if defined(PDF_USE_PARTITION_ALLOC)
pdfium::ConfigurePartitionAllocShimPartitionForTest();
#endif // defined(PDF_USE_PARTITION_ALLOC)
// PDF test environment will be deleted by gtest.
AddGlobalTestEnvironment(new PDFTestEnvironment());
#ifdef PDF_ENABLE_V8
// V8 test environment will be deleted by gtest.
AddGlobalTestEnvironment(new V8TestEnvironment(argv[0]));
#ifdef PDF_ENABLE_XFA
// XFA test environment will be deleted by gtest.
AddGlobalTestEnvironment(new XFATestEnvironment());
#endif // PDF_ENABLE_XFA
#endif // PDF_ENABLE_V8
testing::InitGoogleTest(&argc, argv);
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}