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

Unified Diff: src/profiler/sampling-heap-profiler.cc

Issue 1929813002: Sampling heap profiler: Fix potential crash on accessing scripts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/profiler/sampling-heap-profiler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/profiler/sampling-heap-profiler.cc
diff --git a/src/profiler/sampling-heap-profiler.cc b/src/profiler/sampling-heap-profiler.cc
index 942562dca18c16d0f6322497664a163b6c1f2b3b..6c6e0e597b7e0b6b781881806acd6b09b10dacaa 100644
--- a/src/profiler/sampling-heap-profiler.cc
+++ b/src/profiler/sampling-heap-profiler.cc
@@ -196,7 +196,7 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() {
v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node,
- const std::map<int, Script*>& scripts) {
+ const std::map<int, Handle<Script>>& scripts) {
Local<v8::String> script_name =
ToApiHandle<v8::String>(isolate_->factory()->InternalizeUtf8String(""));
int line = v8::AllocationProfile::kNoLineNumberInfo;
@@ -206,18 +206,17 @@ v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
if (node->script_id_ != v8::UnboundScript::kNoScriptId &&
scripts.find(node->script_id_) != scripts.end()) {
// Cannot use std::map<T>::at because it is not available on android.
- auto non_const_scripts = const_cast<std::map<int, Script*>&>(scripts);
- Script* script = non_const_scripts[node->script_id_];
- if (script) {
+ auto non_const_scripts =
+ const_cast<std::map<int, Handle<Script>>&>(scripts);
+ Handle<Script> script = non_const_scripts[node->script_id_];
+ if (!script.is_null()) {
if (script->name()->IsName()) {
Name* name = Name::cast(script->name());
script_name = ToApiHandle<v8::String>(
isolate_->factory()->InternalizeUtf8String(names_->GetName(name)));
}
- Handle<Script> script_handle(script);
- line = 1 + Script::GetLineNumber(script_handle, node->script_position_);
- column =
- 1 + Script::GetColumnNumber(script_handle, node->script_position_);
+ line = 1 + Script::GetLineNumber(script, node->script_position_);
+ column = 1 + Script::GetColumnNumber(script, node->script_position_);
}
for (auto alloc : node->allocations_) {
allocations.push_back(ScaleSample(alloc.first, alloc.second));
@@ -246,19 +245,15 @@ v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
v8::AllocationProfile* SamplingHeapProfiler::GetAllocationProfile() {
// To resolve positions to line/column numbers, we will need to look up
// scripts. Build a map to allow fast mapping from script id to script.
- std::map<int, Script*> scripts;
+ std::map<int, Handle<Script>> scripts;
{
Script::Iterator iterator(isolate_);
- Script* script;
- while ((script = iterator.Next())) {
- scripts[script->id()] = script;
+ while (Script* script = iterator.Next()) {
+ scripts[script->id()] = handle(script);
}
}
-
auto profile = new v8::internal::AllocationProfile();
-
TranslateAllocationNode(profile, &profile_root_, scripts);
-
return profile;
}
« no previous file with comments | « src/profiler/sampling-heap-profiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698