Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: testing/embedder_test.cpp

Issue 2068563002: Fix memory leaks with V8 startup data. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix non-V8 builds Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/embedder_test.h ('k') | testing/test_support.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/embedder_test.h" 5 #include "testing/embedder_test.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "public/fpdf_dataavail.h" 14 #include "public/fpdf_dataavail.h"
15 #include "public/fpdf_edit.h" 15 #include "public/fpdf_edit.h"
16 #include "public/fpdf_text.h" 16 #include "public/fpdf_text.h"
17 #include "public/fpdfview.h" 17 #include "public/fpdfview.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/test_support.h" 19 #include "testing/test_support.h"
20 #include "testing/utils/path_service.h" 20 #include "testing/utils/path_service.h"
21 21
22 #ifdef PDF_ENABLE_V8 22 #ifdef PDF_ENABLE_V8
23 #include "v8/include/v8-platform.h" 23 #include "v8/include/v8-platform.h"
24 #include "v8/include/v8.h" 24 #include "v8/include/v8.h"
25 #endif // PDF_ENABLE_V8 25 #endif // PDF_ENABLE_V8
26 26
27 namespace { 27 namespace {
28 const char* g_exe_path_ = nullptr; 28
29 const char* g_exe_path = nullptr;
30
31 #ifdef PDF_ENABLE_V8
32 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
33 v8::StartupData* g_v8_natives = nullptr;
34 v8::StartupData* g_v8_snapshot = nullptr;
35 #endif // V8_USE_EXTERNAL_STARTUP_DATA
36 #endif // PDF_ENABLE_V8
37
29 } // namespace 38 } // namespace
30 39
31 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { 40 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) {
32 return true; 41 return true;
33 } 42 }
34 43
35 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} 44 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {}
36 45
37 EmbedderTest::EmbedderTest() 46 EmbedderTest::EmbedderTest()
38 : default_delegate_(new EmbedderTest::Delegate()), 47 : default_delegate_(new EmbedderTest::Delegate()),
39 document_(nullptr), 48 document_(nullptr),
40 form_handle_(nullptr), 49 form_handle_(nullptr),
41 avail_(nullptr), 50 avail_(nullptr),
42 external_isolate_(nullptr), 51 external_isolate_(nullptr),
43 loader_(nullptr), 52 loader_(nullptr),
44 file_length_(0), 53 file_length_(0),
45 file_contents_(nullptr) { 54 file_contents_(nullptr) {
46 memset(&hints_, 0, sizeof(hints_)); 55 memset(&hints_, 0, sizeof(hints_));
47 memset(&file_access_, 0, sizeof(file_access_)); 56 memset(&file_access_, 0, sizeof(file_access_));
48 memset(&file_avail_, 0, sizeof(file_avail_)); 57 memset(&file_avail_, 0, sizeof(file_avail_));
49 delegate_ = default_delegate_.get(); 58 delegate_ = default_delegate_.get();
50 59
51 #ifdef PDF_ENABLE_V8 60 #ifdef PDF_ENABLE_V8
52 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 61 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
53 InitializeV8ForPDFium(g_exe_path_, std::string(), &natives_, &snapshot_, 62 if (g_v8_natives && g_v8_snapshot) {
54 &platform_); 63 InitializeV8ForPDFium(g_exe_path, std::string(), nullptr, nullptr,
64 &platform_);
65 } else {
66 g_v8_natives = new v8::StartupData;
67 g_v8_snapshot = new v8::StartupData;
68 InitializeV8ForPDFium(g_exe_path, std::string(), g_v8_natives,
69 g_v8_snapshot, &platform_);
70 }
55 #else 71 #else
56 InitializeV8ForPDFium(g_exe_path_, &platform_); 72 InitializeV8ForPDFium(g_exe_path, &platform_);
57 #endif // V8_USE_EXTERNAL_STARTUP_DATA 73 #endif // V8_USE_EXTERNAL_STARTUP_DATA
58 #endif // FPDF_ENABLE_V8 74 #endif // FPDF_ENABLE_V8
59 } 75 }
60 76
61 EmbedderTest::~EmbedderTest() { 77 EmbedderTest::~EmbedderTest() {
62 #ifdef PDF_ENABLE_V8 78 #ifdef PDF_ENABLE_V8
63 v8::V8::ShutdownPlatform(); 79 v8::V8::ShutdownPlatform();
64 delete platform_; 80 delete platform_;
65 #endif // PDF_ENABLE_V8 81 #endif // PDF_ENABLE_V8
66 } 82 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info, 328 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info,
313 FPDF_DOCUMENT document, 329 FPDF_DOCUMENT document,
314 int page_index) { 330 int page_index) {
315 EmbedderTest* test = static_cast<EmbedderTest*>(info); 331 EmbedderTest* test = static_cast<EmbedderTest*>(info);
316 return test->delegate_->GetPage(test->form_handle(), document, page_index); 332 return test->delegate_->GetPage(test->form_handle(), document, page_index);
317 } 333 }
318 334
319 // Can't use gtest-provided main since we need to stash the path to the 335 // Can't use gtest-provided main since we need to stash the path to the
320 // executable in order to find the external V8 binary data files. 336 // executable in order to find the external V8 binary data files.
321 int main(int argc, char** argv) { 337 int main(int argc, char** argv) {
322 g_exe_path_ = argv[0]; 338 g_exe_path = argv[0];
323 testing::InitGoogleTest(&argc, argv); 339 testing::InitGoogleTest(&argc, argv);
324 testing::InitGoogleMock(&argc, argv); 340 testing::InitGoogleMock(&argc, argv);
325 return RUN_ALL_TESTS(); 341 int ret_val = RUN_ALL_TESTS();
342
343 #ifdef PDF_ENABLE_V8
344 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
345 if (g_v8_natives)
346 free(const_cast<char*>(g_v8_natives->data));
347 if (g_v8_snapshot)
348 free(const_cast<char*>(g_v8_snapshot->data));
349 #endif // V8_USE_EXTERNAL_STARTUP_DATA
350 #endif // PDF_ENABLE_V8
351
352 return ret_val;
326 } 353 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | testing/test_support.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698