Prechádzať zdrojové kódy

Plug leaks in SynthFS::remove_file().

The process spawn stress test can now run forever. :^)
Andreas Kling 6 rokov pred
rodič
commit
ab72666f48

+ 33 - 0
AK/StringImpl.cpp

@@ -1,6 +1,21 @@
 #include "StringImpl.h"
 #include "StdLibExtras.h"
 #include "kmalloc.h"
+#include "HashTable.h"
+
+#ifdef DEBUG_STRINGIMPL
+unsigned g_stringimpl_count;
+static HashTable<StringImpl*>* g_all_live_stringimpls;
+
+void dump_all_stringimpls()
+{
+    unsigned i = 0;
+    for (auto& it : *g_all_live_stringimpls) {
+        dbgprintf("%u: \"%s\"\n", i, (*it).characters());
+        ++i;
+    }
+}
+#endif
 
 namespace AK {
 
@@ -9,6 +24,10 @@ static StringImpl* s_the_empty_stringimpl = nullptr;
 void StringImpl::initialize_globals()
 {
     s_the_empty_stringimpl = nullptr;
+#ifdef DEBUG_STRINGIMPL
+    g_stringimpl_count = 0;
+    g_all_live_stringimpls = new HashTable<StringImpl*>;
+#endif
 }
 
 StringImpl& StringImpl::the_empty_stringimpl()
@@ -18,8 +37,22 @@ StringImpl& StringImpl::the_empty_stringimpl()
     return *s_the_empty_stringimpl;
 }
 
+StringImpl::StringImpl(ConstructWithInlineBufferTag, size_t length)
+    : m_length(length)
+    , m_characters(m_inline_buffer)
+{
+#ifdef DEBUG_STRINGIMPL
+    ++g_stringimpl_count;
+    g_all_live_stringimpls->set(this);
+#endif
+}
+
 StringImpl::~StringImpl()
 {
+#ifdef DEBUG_STRINGIMPL
+    --g_stringimpl_count;
+    g_all_live_stringimpls->remove(this);
+#endif
 }
 
 static inline size_t allocationSizeForStringImpl(size_t length)

+ 1 - 1
AK/StringImpl.h

@@ -37,7 +37,7 @@ private:
     explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { }
 
     enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer };
-    explicit StringImpl(ConstructWithInlineBufferTag, size_t length) : m_length(length), m_characters(m_inline_buffer) { }
+    StringImpl(ConstructWithInlineBufferTag, size_t length);
 
     void compute_hash() const;
 

+ 5 - 1
VirtualFileSystem/SyntheticFileSystem.cpp

@@ -116,8 +116,12 @@ bool SynthFS::remove_file(InodeIndex inode)
         break;
     }
 
+    Vector<InodeIndex> indices_to_remove;
+    indices_to_remove.ensureCapacity(file.m_children.size());
     for (auto& child : file.m_children)
-        remove_file(child->m_metadata.inode.index());
+        indices_to_remove.unchecked_append(child->m_metadata.inode.index());
+    for (auto& index : indices_to_remove)
+        remove_file(index);
     m_inodes.remove(inode);
     return true;
 }