Plug leaks in SynthFS::remove_file().

The process spawn stress test can now run forever. :^)
This commit is contained in:
Andreas Kling 2018-12-28 03:09:45 +01:00
parent 3f3535213b
commit ab72666f48
3 changed files with 39 additions and 2 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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;
}