Fix memory leak in fxge.SkiaState tests. In Harness(), CFX_DIBitmap::Create() allocates memory for |bitmap| but the memory never gets freed at the end of the function. Use ScopedFPDFBitmap to automatically destroy |bitmap| when Harness() finishes to avoid the memory leak. Bug: pdfium:1378 Change-Id: I84e87238734a05c1a711a3889b48f01cb5751ee2 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/59310 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp index 588cb96..48734ee 100644 --- a/core/fxge/skia/fx_skia_device_embeddertest.cpp +++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp
@@ -10,6 +10,7 @@ #include "core/fxge/skia/fx_skia_device.h" #include "core/fxge/text_char_pos.h" #include "fpdfsdk/cpdfsdk_helpers.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdfview.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkPictureRecorder.h" @@ -120,13 +121,13 @@ const State& state) { int h = 1; int w = 4; - FPDF_BITMAP bitmap = FPDFBitmap_Create(w, h, 1); + ScopedFPDFBitmap bitmap(FPDFBitmap_Create(w, h, 1)); EXPECT_NE(nullptr, bitmap); if (!bitmap) return; - FPDFBitmap_FillRect(bitmap, 0, 0, w, h, 0x00000000); + FPDFBitmap_FillRect(bitmap.get(), 0, 0, w, h, 0x00000000); CFX_DefaultRenderDevice geDevice; - RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap)); + RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap.get())); geDevice.Attach(pBitmap, false, nullptr, false); CFX_SkiaDeviceDriver* driver = static_cast<CFX_SkiaDeviceDriver*>(geDevice.GetDeviceDriver());