Bug 1187450 - avoid leaking cstr in SPSProfiler::allocProfileString. r?jorendorff draft
authorBogdan Postelnicu <bogdan.postelnicu@softvision.ro>
Tue, 23 Feb 2016 11:12:35 +0200
changeset 333279 a326ac8d007d5ccc7260bdd23830ee9ed084bf45
parent 332881 789a12291942763bc1e3a89f97e0b82dc1c9d00b
child 514694 72c01a4b940e48fff15eda64eae0e9d72ff894f1
push id11321
push userBogdan.Postelnicu@softvision.ro
push dateTue, 23 Feb 2016 09:14:04 +0000
reviewersjorendorff
bugs1187450
milestone47.0a1
Bug 1187450 - avoid leaking cstr in SPSProfiler::allocProfileString. r?jorendorff MozReview-Commit-ID: GtBKL4M2hfm
js/src/vm/SPSProfiler.cpp
--- 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;