Bug 1187450 - avoid leaking cstr in SPSProfiler::allocProfileString. r?jorendorff
MozReview-Commit-ID: GtBKL4M2hfm
--- a/js/src/vm/SPSProfiler.cpp
+++ b/js/src/vm/SPSProfiler.cpp
@@ -345,18 +345,20 @@ SPSProfiler::allocProfileString(JSScript
char* cstr = js_pod_malloc<char>(len + 1);
if (cstr == nullptr)
return nullptr;
// Construct the descriptive string.
DebugOnly<size_t> ret;
if (atom) {
UniqueChars atomStr = StringToNewUTF8CharsZ(nullptr, *atom);
- if (!atomStr)
+ if (!atomStr) {
+ js_free(cstr);
return nullptr;
+ }
ret = JS_snprintf(cstr, len + 1, "%s (%s:%" PRIu64 ")", atomStr.get(), filename, lineno);
} else {
ret = JS_snprintf(cstr, len + 1, "%s:%" PRIu64, filename, lineno);
}
MOZ_ASSERT(ret == len, "Computed length should match actual length!");
return cstr;