From 209153d1925cd0cbfe942edc6179030f7243e400 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Tue, 5 May 2015 17:59:09 -0700 Subject: [PATCH] Fix up strings Sky passes to base/trace_event String parameters passed to the trace macros in base/trace_event must either be std::string (which Sky doesn't use very much), pointers to null terminated C-style strings that live forever (like a string literal) pointers to C-style strings that are annotated by macro as needing to be copied. This fixes up a few instances that passed pointers to temporary strings without the copying annotation or pointers to non-null-terminated strings so the trace data doesn't have random garbage memory in it. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/1107853003 --- engine/core/events/GenericEventQueue.cpp | 14 +++++++++++--- engine/core/fetch/ResourceFetcher.cpp | 5 ++++- engine/core/frame/Tracing.cpp | 8 ++++++-- engine/web/WebViewImpl.cpp | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/engine/core/events/GenericEventQueue.cpp b/engine/core/events/GenericEventQueue.cpp index f1662fd91f6..056cbbc0530 100644 --- a/engine/core/events/GenericEventQueue.cpp +++ b/engine/core/events/GenericEventQueue.cpp @@ -56,7 +56,9 @@ bool GenericEventQueue::enqueueEvent(PassRefPtr event) if (event->target() == m_owner) event->setTarget(nullptr); - TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.get(), "type", event->type().ascii().data()); + TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", + event.get(), "type", + TRACE_STR_COPY(event->type().ascii().data())); m_pendingEvents.append(event); if (!m_timer.isActive()) @@ -71,7 +73,10 @@ bool GenericEventQueue::cancelEvent(Event* event) if (found) { m_pendingEvents.remove(m_pendingEvents.find(event)); - TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii().data(), "status", "cancelled"); + TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, + "type", + TRACE_STR_COPY(event->type().ascii().data()), + "status", "cancelled"); } if (m_pendingEvents.isEmpty()) @@ -111,7 +116,10 @@ void GenericEventQueue::cancelAllEvents() for (size_t i = 0; i < m_pendingEvents.size(); ++i) { Event* event = m_pendingEvents[i].get(); - TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii().data(), "status", "cancelled"); + TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, + "type", + TRACE_STR_COPY(event->type().ascii().data()), + "status", "cancelled"); } m_pendingEvents.clear(); } diff --git a/engine/core/fetch/ResourceFetcher.cpp b/engine/core/fetch/ResourceFetcher.cpp index 913482074e1..ec4ab7aac8b 100644 --- a/engine/core/fetch/ResourceFetcher.cpp +++ b/engine/core/fetch/ResourceFetcher.cpp @@ -694,7 +694,10 @@ void ResourceFetcher::willTerminateResourceLoader(ResourceLoader* loader) void ResourceFetcher::willStartLoadingResource(Resource* resource, ResourceRequest& request) { - TRACE_EVENT_ASYNC_BEGIN2("net", "Resource", resource, "url", resource->url().string().ascii().data(), "priority", resource->resourceRequest().priority()); + TRACE_EVENT_ASYNC_BEGIN2( + "net", "Resource", resource, "url", + TRACE_STR_COPY(resource->url().string().ascii().data()), "priority", + resource->resourceRequest().priority()); } void ResourceFetcher::stopFetching() diff --git a/engine/core/frame/Tracing.cpp b/engine/core/frame/Tracing.cpp index 3359da2abb7..f05932615f1 100644 --- a/engine/core/frame/Tracing.cpp +++ b/engine/core/frame/Tracing.cpp @@ -21,13 +21,17 @@ Tracing::~Tracing() void Tracing::begin(const String& name) { StringUTF8Adaptor utf8(name); - TRACE_EVENT_COPY_BEGIN0("script", utf8.data()); + // TRACE_EVENT_COPY_BEGIN0 needs a c-style null-terminated string. + CString cstring(utf8.data(), utf8.length()); + TRACE_EVENT_COPY_BEGIN0("script", cstring.data()); } void Tracing::end(const String& name) { StringUTF8Adaptor utf8(name); - TRACE_EVENT_COPY_END0("script", utf8.data()); + // TRACE_EVENT_COPY_END0 needs a c-style null-terminated string. + CString cstring(utf8.data(), utf8.length()); + TRACE_EVENT_COPY_END0("script", cstring.data()); } } // namespace blink diff --git a/engine/web/WebViewImpl.cpp b/engine/web/WebViewImpl.cpp index f62e9b4d794..342bd53d669 100644 --- a/engine/web/WebViewImpl.cpp +++ b/engine/web/WebViewImpl.cpp @@ -311,7 +311,8 @@ static String inputTypeToName(WebInputEvent::Type type) bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent) { - TRACE_EVENT1("input", "WebViewImpl::handleInputEvent", "type", inputTypeToName(inputEvent.type).ascii().data()); + TRACE_EVENT1("input", "WebViewImpl::handleInputEvent", "type", + TRACE_STR_COPY(inputTypeToName(inputEvent.type).ascii().data())); if (WebInputEvent::isPointerEventType(inputEvent.type)) { const WebPointerEvent& event = static_cast(inputEvent);