Bug 948327 - Do not leak the payload object passed to mozilla_sampler_add_marker() if we don't end up using it; r=BenWa

This commit is contained in:
Ehsan Akhgari 2013-12-10 16:34:19 -05:00
parent 66b63f6557
commit e276af8c8e
3 changed files with 30 additions and 24 deletions

View File

@ -26,8 +26,8 @@ class ProfilerMarkerPayload;
inline void* mozilla_sampler_call_enter(const char *aInfo, void *aFrameAddress = nullptr,
bool aCopy = false, uint32_t line = 0);
inline void mozilla_sampler_call_exit(void* handle);
inline void mozilla_sampler_add_marker(const char *aInfo,
ProfilerMarkerPayload *aPayload = nullptr);
void mozilla_sampler_add_marker(const char *aInfo,
ProfilerMarkerPayload *aPayload = nullptr);
void mozilla_sampler_start(int aEntries, double aInterval,
const char** aFeatures, uint32_t aFeatureCount,

View File

@ -366,27 +366,6 @@ inline void mozilla_sampler_call_exit(void *aHandle)
stack->pop();
}
inline void mozilla_sampler_add_marker(const char *aMarker, ProfilerMarkerPayload *aPayload)
{
if (!stack_key_initialized)
return;
// Don't insert a marker if we're not profiling to avoid
// the heap copy (malloc).
if (!profiler_is_active()) {
return;
}
// Don't add a marker if we don't want to include personal information
if (profiler_in_privacy_mode()) {
return;
}
PseudoStack *stack = tlsPseudoStack.get();
if (!stack) {
return;
}
stack->addMarker(aMarker, aPayload);
}
void mozilla_sampler_add_marker(const char *aMarker, ProfilerMarkerPayload *aPayload);
#endif /* ndef TOOLS_SPS_SAMPLER_H_ */

View File

@ -872,6 +872,33 @@ void mozilla_sampler_tracing(const char* aCategory, const char* aInfo,
mozilla_sampler_add_marker(aInfo, new ProfilerMarkerTracing(aCategory, aMetaData));
}
void mozilla_sampler_add_marker(const char *aMarker, ProfilerMarkerPayload *aPayload)
{
// Note that aPayload may be allocated by the caller, so we need to make sure
// that we free it at some point.
nsAutoPtr<ProfilerMarkerPayload> payload(aPayload);
if (!stack_key_initialized)
return;
// Don't insert a marker if we're not profiling to avoid
// the heap copy (malloc).
if (!profiler_is_active()) {
return;
}
// Don't add a marker if we don't want to include personal information
if (profiler_in_privacy_mode()) {
return;
}
PseudoStack *stack = tlsPseudoStack.get();
if (!stack) {
return;
}
stack->addMarker(aMarker, payload.forget());
}
// END externally visible functions
////////////////////////////////////////////////////////////////////////