Bug 971094 - Part 0: Add some null checks to the profiler's usage of Observation::Filename(). r=BenWa
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Thu, 20 Feb 2014 08:43:55 -0500
changeset 170036 370a4a9486a62f2be27f48aaba1687cc5df4d734
parent 170035 4b1c8bd01d3d9de7278fb7c58ac38628c0df7abe
child 170037 6ef599b12a44a271458404b9b51f343413b41bee
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersBenWa
bugs971094
milestone30.0a1
Bug 971094 - Part 0: Add some null checks to the profiler's usage of Observation::Filename(). r=BenWa
tools/profiler/ProfilerIOInterposeObserver.cpp
tools/profiler/ProfilerMarkers.cpp
--- a/tools/profiler/ProfilerIOInterposeObserver.cpp
+++ b/tools/profiler/ProfilerIOInterposeObserver.cpp
@@ -31,16 +31,20 @@ void ProfilerIOInterposeObserver::Observ
     case IOInterposeObserver::OpClose:
       str = "close";
       break;
     default:
       return;
   }
   ProfilerBacktrace* stack = profiler_get_backtrace();
 
-  IOMarkerPayload* markerPayload = new IOMarkerPayload(
-                           aObservation.Reference(),
-                           NS_ConvertUTF16toUTF8(aObservation.Filename()).get(),
-                           aObservation.Start(),
-                           aObservation.End(),
-                           stack);
+  nsCString filename;
+  if (aObservation.Filename()) {
+    filename = NS_ConvertUTF16toUTF8(aObservation.Filename());
+  }
+
+  IOMarkerPayload* markerPayload = new IOMarkerPayload(aObservation.Reference(),
+                                                       filename.get(),
+                                                       aObservation.Start(),
+                                                       aObservation.End(),
+                                                       stack);
   PROFILER_MARKER_PAYLOAD(str, markerPayload);
 }
--- a/tools/profiler/ProfilerMarkers.cpp
+++ b/tools/profiler/ProfilerMarkers.cpp
@@ -110,19 +110,19 @@ template JSObjectBuilder::Object
 ProfilerMarkerImagePayload::preparePayloadImp<JSObjectBuilder>(JSObjectBuilder& b);
 
 IOMarkerPayload::IOMarkerPayload(const char* aSource,
                                  const char* aFilename,
                                  const mozilla::TimeStamp& aStartTime,
                                  const mozilla::TimeStamp& aEndTime,
                                  ProfilerBacktrace* aStack)
   : ProfilerMarkerPayload(aStartTime, aEndTime, aStack),
-    mSource(aSource),
-    mFilename(strdup(aFilename))
+    mSource(aSource)
 {
+  mFilename = aFilename ? strdup(aFilename) : nullptr;
   MOZ_ASSERT(aSource);
 }
 
 IOMarkerPayload::~IOMarkerPayload(){
   free(mFilename);
 }
 
 template<typename Builder> typename Builder::Object