[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

kbr at google.com kbr at google.com
Wed Dec 22 13:14:42 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 051c50aba176794e18aef5fe86da2b7b840609c8
Author: kbr at google.com <kbr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Sep 9 18:20:54 2010 +0000

    2010-09-09  Kenneth Russell  <kbr at google.com>
    
            Reviewed by James Robinson.
    
            Memory leak in red/black tree
            https://bugs.webkit.org/show_bug.cgi?id=45472
    
            Fixed memory leak in red/black tree where it was using operator
            new directly to allocate its internal nodes rather than the arena
            with which it was configured. Added allocateObject variant to
            arena supporting single-argument constructors. Added test to
            red/black tree unit tests to cover this functionality, and
            refactored TrackedAllocator into helper file to share between
            arena and red/black tree tests.
    
            * WebKit.gyp:
            * tests/ArenaTestHelpers.h: Added.
            (WebCore::ArenaTestHelpers::TrackedAllocator::create):
            (WebCore::ArenaTestHelpers::TrackedAllocator::allocate):
            (WebCore::ArenaTestHelpers::TrackedAllocator::free):
            (WebCore::ArenaTestHelpers::TrackedAllocator::isEmpty):
            (WebCore::ArenaTestHelpers::TrackedAllocator::numRegions):
            (WebCore::ArenaTestHelpers::TrackedAllocator::TrackedAllocator):
            * tests/PODArenaTest.cpp:
            * tests/PODRedBlackTreeTest.cpp:
            (WebCore::TEST):
    2010-09-09  Kenneth Russell  <kbr at google.com>
    
            Reviewed by James Robinson.
    
            Memory leak in red/black tree
            https://bugs.webkit.org/show_bug.cgi?id=45472
    
            Fixed memory leak in red/black tree where it was using operator
            new directly to allocate its internal nodes rather than the arena
            with which it was configured. Added allocateObject variant to
            arena supporting single-argument constructors. Added test to
            red/black tree unit tests to cover this functionality, and
            refactored TrackedAllocator into helper file to share between
            arena and red/black tree tests.
    
            * platform/graphics/gpu/PODArena.h:
            (WebCore::PODArena::allocateObject):
            (WebCore::PODArena::allocateBase):
            * platform/graphics/gpu/PODIntervalTree.h:
            (WebCore::PODIntervalTree::PODIntervalTree):
            * platform/graphics/gpu/PODRedBlackTree.h:
            (WebCore::PODRedBlackTree::add):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67099 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index fd4846a..46f133d 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,26 @@
+2010-09-09  Kenneth Russell  <kbr at google.com>
+
+        Reviewed by James Robinson.
+
+        Memory leak in red/black tree
+        https://bugs.webkit.org/show_bug.cgi?id=45472
+
+        Fixed memory leak in red/black tree where it was using operator
+        new directly to allocate its internal nodes rather than the arena
+        with which it was configured. Added allocateObject variant to
+        arena supporting single-argument constructors. Added test to
+        red/black tree unit tests to cover this functionality, and
+        refactored TrackedAllocator into helper file to share between
+        arena and red/black tree tests.
+
+        * platform/graphics/gpu/PODArena.h:
+        (WebCore::PODArena::allocateObject):
+        (WebCore::PODArena::allocateBase):
+        * platform/graphics/gpu/PODIntervalTree.h:
+        (WebCore::PODIntervalTree::PODIntervalTree):
+        * platform/graphics/gpu/PODRedBlackTree.h:
+        (WebCore::PODRedBlackTree::add):
+
 2010-09-09  Dean Jackson  <dino at apple.com>
 
         Reviewed by Simon Fraser.
diff --git a/WebCore/platform/graphics/gpu/PODArena.h b/WebCore/platform/graphics/gpu/PODArena.h
index 08326e9..f68baef 100644
--- a/WebCore/platform/graphics/gpu/PODArena.h
+++ b/WebCore/platform/graphics/gpu/PODArena.h
@@ -86,24 +86,22 @@ public:
     // Allocates an object from the arena.
     template<class T> T* allocateObject()
     {
-        void* ptr = 0;
-        size_t roundedSize = roundUp(sizeof(T), minAlignment<T>());
-        if (m_current)
-            ptr = m_current->allocate(roundedSize);
-
-        if (!ptr) {
-            if (roundedSize > m_currentChunkSize)
-                m_currentChunkSize = roundedSize;
-            m_chunks.append(adoptPtr(new Chunk(m_allocator.get(), m_currentChunkSize)));
-            m_current = m_chunks.last().get();
-            ptr = m_current->allocate(roundedSize);
-        }
-
+        void* ptr = allocateBase<T>();
         if (ptr) {
             // Use placement operator new to allocate a T at this location.
             new(ptr) T();
         }
+        return static_cast<T*>(ptr);
+    }
 
+    // Allocates an object from the arena, calling a single-argument constructor.
+    template<class T, class Argument1Type> T* allocateObject(const Argument1Type& argument1)
+    {
+        void* ptr = allocateBase<T>();
+        if (ptr) {
+            // Use placement operator new to allocate a T at this location.
+            new(ptr) T(argument1);
+        }
         return static_cast<T*>(ptr);
     }
 
@@ -135,6 +133,23 @@ private:
         return WTF_ALIGN_OF(T);
     }
 
+    template<class T> void* allocateBase()
+    {
+        void* ptr = 0;
+        size_t roundedSize = roundUp(sizeof(T), minAlignment<T>());
+        if (m_current)
+            ptr = m_current->allocate(roundedSize);
+
+        if (!ptr) {
+            if (roundedSize > m_currentChunkSize)
+                m_currentChunkSize = roundedSize;
+            m_chunks.append(adoptPtr(new Chunk(m_allocator.get(), m_currentChunkSize)));
+            m_current = m_chunks.last().get();
+            ptr = m_current->allocate(roundedSize);
+        }
+        return ptr;
+    }
+
     // Rounds up the given allocation size to the specified alignment.
     size_t roundUp(size_t size, size_t alignment)
     {
diff --git a/WebCore/platform/graphics/gpu/PODIntervalTree.h b/WebCore/platform/graphics/gpu/PODIntervalTree.h
index c8a75cb..c0a86aa 100644
--- a/WebCore/platform/graphics/gpu/PODIntervalTree.h
+++ b/WebCore/platform/graphics/gpu/PODIntervalTree.h
@@ -52,7 +52,7 @@ public:
         init();
     }
 
-    explicit PODIntervalTree(PODArena* arena)
+    explicit PODIntervalTree(PassRefPtr<PODArena> arena)
         : PODRedBlackTree<IntervalType>(arena)
     {
         init();
diff --git a/WebCore/platform/graphics/gpu/PODRedBlackTree.h b/WebCore/platform/graphics/gpu/PODRedBlackTree.h
index fd8120b..9b02037 100644
--- a/WebCore/platform/graphics/gpu/PODRedBlackTree.h
+++ b/WebCore/platform/graphics/gpu/PODRedBlackTree.h
@@ -122,7 +122,7 @@ public:
 
     void add(const T& data)
     {
-        Node* node = new Node(data);
+        Node* node = m_arena->allocateObject<Node, T>(data);
         insertNode(node);
     }
 
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index 9992d10..3ac5fd4 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,30 @@
+2010-09-09  Kenneth Russell  <kbr at google.com>
+
+        Reviewed by James Robinson.
+
+        Memory leak in red/black tree
+        https://bugs.webkit.org/show_bug.cgi?id=45472
+
+        Fixed memory leak in red/black tree where it was using operator
+        new directly to allocate its internal nodes rather than the arena
+        with which it was configured. Added allocateObject variant to
+        arena supporting single-argument constructors. Added test to
+        red/black tree unit tests to cover this functionality, and
+        refactored TrackedAllocator into helper file to share between
+        arena and red/black tree tests.
+
+        * WebKit.gyp:
+        * tests/ArenaTestHelpers.h: Added.
+        (WebCore::ArenaTestHelpers::TrackedAllocator::create):
+        (WebCore::ArenaTestHelpers::TrackedAllocator::allocate):
+        (WebCore::ArenaTestHelpers::TrackedAllocator::free):
+        (WebCore::ArenaTestHelpers::TrackedAllocator::isEmpty):
+        (WebCore::ArenaTestHelpers::TrackedAllocator::numRegions):
+        (WebCore::ArenaTestHelpers::TrackedAllocator::TrackedAllocator):
+        * tests/PODArenaTest.cpp:
+        * tests/PODRedBlackTreeTest.cpp:
+        (WebCore::TEST):
+
 2010-09-09  Tony Chang  <tony at chromium.org>
 
         Reviewed by Dimitri Glazkov.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index e4b3dfe..11246fa 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -733,6 +733,7 @@
                         'src',
                     ],
                     'sources': [
+                        'tests/ArenaTestHelpers.h',
                         'tests/DragImageTest.cpp',
                         'tests/IDBBindingUtilitiesTest.cpp',
                         'tests/IDBKeyPathTest.cpp',
diff --git a/WebKit/chromium/tests/ArenaTestHelpers.h b/WebKit/chromium/tests/ArenaTestHelpers.h
new file mode 100644
index 0000000..87f827d
--- /dev/null
+++ b/WebKit/chromium/tests/ArenaTestHelpers.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ArenaTestHelpers_h
+#define ArenaTestHelpers_h
+
+#include "PODArena.h"
+#include <gtest/gtest.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+namespace ArenaTestHelpers {
+
+// An allocator for the PODArena which tracks the regions which have
+// been allocated.
+class TrackedAllocator : public PODArena::FastMallocAllocator {
+public:
+    static PassRefPtr<TrackedAllocator> create()
+    {
+        return adoptRef(new TrackedAllocator);
+    }
+
+    virtual void* allocate(size_t size)
+    {
+        void* result = PODArena::FastMallocAllocator::allocate(size);
+        m_allocatedRegions.append(result);
+        return result;
+    }
+
+    virtual void free(void* ptr)
+    {
+        size_t slot = m_allocatedRegions.find(ptr);
+        ASSERT_GE(slot, 0);
+        m_allocatedRegions.remove(slot);
+        PODArena::FastMallocAllocator::free(ptr);
+    }
+
+    bool isEmpty() const
+    {
+        return !numRegions();
+    }
+
+    int numRegions() const
+    {
+        return m_allocatedRegions.size();
+    }
+
+private:
+    TrackedAllocator() { }
+    Vector<void*> m_allocatedRegions;
+};
+
+} // namespace ArenaTestHelpers
+} // namespace WebCore
+
+#endif // ArenaTestHelpers_h
diff --git a/WebKit/chromium/tests/PODArenaTest.cpp b/WebKit/chromium/tests/PODArenaTest.cpp
index 26ace5f..c5b1ede 100644
--- a/WebKit/chromium/tests/PODArenaTest.cpp
+++ b/WebKit/chromium/tests/PODArenaTest.cpp
@@ -27,6 +27,7 @@
 
 #include "PODArena.h"
 
+#include "ArenaTestHelpers.h"
 #include <algorithm>
 #include <gtest/gtest.h>
 #include <wtf/FastMalloc.h>
@@ -35,46 +36,9 @@
 
 namespace WebCore {
 
-namespace {
-
-// An allocator for the PODArena which tracks the regions which have
-// been allocated.
-class TrackedAllocator : public PODArena::FastMallocAllocator {
-public:
-    static PassRefPtr<TrackedAllocator> create()
-    {
-        return adoptRef(new TrackedAllocator);
-    }
-
-    virtual void* allocate(size_t size)
-    {
-        void* result = PODArena::FastMallocAllocator::allocate(size);
-        m_allocatedRegions.append(result);
-        return result;
-    }
-
-    virtual void free(void* ptr)
-    {
-        size_t slot = m_allocatedRegions.find(ptr);
-        ASSERT_GE(slot, 0);
-        m_allocatedRegions.remove(slot);
-        PODArena::FastMallocAllocator::free(ptr);
-    }
+using ArenaTestHelpers::TrackedAllocator;
 
-    bool isEmpty() const
-    {
-        return !numRegions();
-    }
-
-    int numRegions() const
-    {
-        return m_allocatedRegions.size();
-    }
-
-private:
-    TrackedAllocator() { }
-    Vector<void*> m_allocatedRegions;
-};
+namespace {
 
 // A couple of simple structs to allocate.
 struct TestClass1 {
diff --git a/WebKit/chromium/tests/PODRedBlackTreeTest.cpp b/WebKit/chromium/tests/PODRedBlackTreeTest.cpp
index 0a995a9..0cc10e7 100644
--- a/WebKit/chromium/tests/PODRedBlackTreeTest.cpp
+++ b/WebKit/chromium/tests/PODRedBlackTreeTest.cpp
@@ -29,16 +29,32 @@
 
 #include "PODRedBlackTree.h"
 
+#include "ArenaTestHelpers.h"
 #include "TreeTestHelpers.h"
 #include <gtest/gtest.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
+using ArenaTestHelpers::TrackedAllocator;
 using TreeTestHelpers::generateSeed;
 using TreeTestHelpers::initRandom;
 using TreeTestHelpers::nextRandom;
 
+TEST(PODRedBlackTreeTest, TestTreeAllocatesFromArena)
+{
+    RefPtr<TrackedAllocator> allocator = TrackedAllocator::create();
+    {
+        RefPtr<PODArena> arena = PODArena::create(allocator);
+        PODRedBlackTree<int> tree(arena);
+        int numAdditions = 2 * PODArena::DefaultChunkSize / sizeof(int);
+        for (int i = 0; i < numAdditions; ++i)
+            tree.add(i);
+        EXPECT_GT(allocator->numRegions(), 1);
+    }
+    EXPECT_EQ(allocator->numRegions(), 0);
+}
+
 TEST(PODRedBlackTreeTest, TestSingleElementInsertion)
 {
     PODRedBlackTree<int> tree;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list