Bug 1493458 - Free string buffer using Truncate() after testing SetCapacity(). r=erahm
authorHenri Sivonen <hsivonen@hsivonen.fi>
Wed, 21 Nov 2018 15:27:04 +0000
changeset 506909 5b09820ac9bd607d41c64386ce7be1b15d70e959
parent 506908 240b08a258e907a50403beb079e2afbcd456a3f8
child 506910 fd219dda36e80a8da14f65c11db66f42c4d31982
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1493458
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1493458 - Free string buffer using Truncate() after testing SetCapacity(). r=erahm Differential Revision: https://phabricator.services.mozilla.com/D12538
xpcom/tests/gtest/TestStrings.cpp
--- a/xpcom/tests/gtest/TestStrings.cpp
+++ b/xpcom/tests/gtest/TestStrings.cpp
@@ -1397,83 +1397,83 @@ TEST_F(Strings, huge_capacity)
   nsString a, b, c, d, e, f, g, h, i, j, k, l, m, n;
   nsCString n1;
 
   // Ignore the result if the address space is less than 64-bit because
   // some of the allocations above will exhaust the address space.
   if (sizeof(void*) >= 8) {
     EXPECT_TRUE(a.SetCapacity(1, fallible));
     EXPECT_FALSE(a.SetCapacity(nsString::size_type(-1)/2, fallible));
-    EXPECT_TRUE(a.SetCapacity(0, fallible));  // free the allocated memory
+    a.Truncate();  // free the allocated memory
 
     EXPECT_TRUE(b.SetCapacity(1, fallible));
     EXPECT_FALSE(b.SetCapacity(nsString::size_type(-1)/2 - 1, fallible));
-    EXPECT_TRUE(b.SetCapacity(0, fallible));
+    b.Truncate();
 
     EXPECT_TRUE(c.SetCapacity(1, fallible));
     EXPECT_FALSE(c.SetCapacity(nsString::size_type(-1)/2, fallible));
-    EXPECT_TRUE(c.SetCapacity(0, fallible));
+    c.Truncate();
 
     EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2 - 1, fallible));
     EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2, fallible));
-    EXPECT_TRUE(d.SetCapacity(0, fallible));
+    d.Truncate();
 
     EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4, fallible));
     EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
-    EXPECT_TRUE(e.SetCapacity(0, fallible));
+    e.Truncate();
 
     EXPECT_FALSE(f.SetCapacity(nsString::size_type(-1)/2, fallible));
-    EXPECT_TRUE(f.SetCapacity(0, fallible));
+    f.Truncate();
 
     EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1000, fallible));
     EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1001, fallible));
-    EXPECT_TRUE(g.SetCapacity(0, fallible));
+    g.Truncate();
 
     EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/4+1, fallible));
     EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/2, fallible));
-    EXPECT_TRUE(h.SetCapacity(0, fallible));
+    h.Truncate();
 
     EXPECT_TRUE(i.SetCapacity(1, fallible));
     EXPECT_TRUE(i.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible));
     EXPECT_FALSE(i.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
-    EXPECT_TRUE(i.SetCapacity(0, fallible));
+    i.Truncate();
 
     EXPECT_TRUE(j.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible));
     EXPECT_FALSE(j.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
-    EXPECT_TRUE(j.SetCapacity(0, fallible));
+    j.Truncate();
 
     EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/8 - 1000, fallible));
     EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 1001, fallible));
     EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 998, fallible));
     EXPECT_FALSE(k.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
-    EXPECT_TRUE(k.SetCapacity(0, fallible));
+    k.Truncate();
 
     EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8, fallible));
     EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 1, fallible));
     EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 2, fallible));
-    EXPECT_TRUE(l.SetCapacity(0, fallible));
+    l.Truncate();
 
     EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1000, fallible));
     EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1001, fallible));
-    EXPECT_TRUE(m.SetCapacity(0, fallible));
+    m.Truncate();
 
     EXPECT_TRUE(n.SetCapacity(nsString::size_type(-1)/8+1, fallible));
     EXPECT_FALSE(n.SetCapacity(nsString::size_type(-1)/4, fallible));
-    EXPECT_TRUE(n.SetCapacity(0, fallible));
+    n.Truncate();
 
-    EXPECT_TRUE(n.SetCapacity(0, fallible));
+    n.Truncate();
     EXPECT_TRUE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 2, fallible));
-    EXPECT_TRUE(n.SetCapacity(0, fallible));
+    n.Truncate();
     EXPECT_FALSE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 1, fallible));
-    EXPECT_TRUE(n.SetCapacity(0, fallible));
-    EXPECT_TRUE(n1.SetCapacity(0, fallible));
+    n.Truncate();
+    n1.Truncate();
     EXPECT_TRUE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 2, fallible));
-    EXPECT_TRUE(n1.SetCapacity(0, fallible));
+    n1.Truncate();
     EXPECT_FALSE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 1, fallible));
-    EXPECT_TRUE(n1.SetCapacity(0, fallible));
+    n1.Truncate();
   }
 }
 
 static void test_tofloat_helper(const nsString& aStr, float aExpected, bool aSuccess)
 {
   nsresult result;
   EXPECT_EQ(aStr.ToFloat(&result), aExpected);
   if (aSuccess) {