Bug 1434206 - Keep TableUpdate objects in smart pointers. r=gcp

Manually keeping tabs on the lifetime of these objects is a pain
and is the likely source of some of our crashes. I suspect we might
also be leaking memory.

This change creates an explicit copy of the main array into the
update thread to avoid using a non-thread-safe shared data
structure. This is a shallow copy. Only the pointers to the
TableUpdates are copied, which means one pointer per list (e.g. 5
in total for google4 in a new profile).

MozReview-Commit-ID: 221d6GkKt0M
This commit is contained in:
Francois Marier
2018-06-01 15:48:48 -07:00
parent 6f76ad1921
commit ef8ea55aca
13 changed files with 149 additions and 183 deletions

View File

@@ -78,16 +78,6 @@ ProtocolParser::ProtocolParser()
ProtocolParser::~ProtocolParser()
{
CleanupUpdates();
}
void
ProtocolParser::CleanupUpdates()
{
for (uint32_t i = 0; i < mTableUpdates.Length(); i++) {
delete mTableUpdates[i];
}
mTableUpdates.Clear();
}
nsresult
@@ -109,7 +99,7 @@ ProtocolParser::Begin(const nsACString& aTable,
return NS_OK;
}
TableUpdate *
RefPtr<TableUpdate>
ProtocolParser::GetTableUpdate(const nsACString& aTable)
{
for (uint32_t i = 0; i < mTableUpdates.Length(); i++) {
@@ -122,7 +112,7 @@ ProtocolParser::GetTableUpdate(const nsACString& aTable)
// updates can be transferred to DBServiceWorker, which passes
// them back to Classifier when doing the updates, and that
// will free them.
TableUpdate *update = CreateTableUpdate(aTable);
RefPtr<TableUpdate> update = CreateTableUpdate(aTable);
mTableUpdates.AppendElement(update);
return update;
}
@@ -143,7 +133,7 @@ ProtocolParserV2::~ProtocolParserV2()
void
ProtocolParserV2::SetCurrentTable(const nsACString& aTable)
{
auto update = GetTableUpdate(aTable);
RefPtr<TableUpdate> update = GetTableUpdate(aTable);
mTableUpdate = TableUpdate::Cast<TableUpdateV2>(update);
}
@@ -698,7 +688,7 @@ ProtocolParserV2::ProcessHostAddComplete(uint8_t aNumEntries,
nsresult
ProtocolParserV2::ProcessHostSubComplete(uint8_t aNumEntries,
const nsACString& aChunk, uint32_t* aStart)
const nsACString& aChunk, uint32_t* aStart)
{
MOZ_ASSERT(mTableUpdate);
NS_ASSERTION(mChunkState.hashSize == COMPLETE_SIZE,
@@ -748,7 +738,7 @@ ProtocolParserV2::NextLine(nsACString& aLine)
return true;
}
TableUpdate*
RefPtr<TableUpdate>
ProtocolParserV2::CreateTableUpdate(const nsACString& aTableName) const
{
return new TableUpdateV2(aTableName);
@@ -773,7 +763,7 @@ ProtocolParserProtobuf::SetCurrentTable(const nsACString& aTable)
}
TableUpdate*
RefPtr<TableUpdate>
ProtocolParserProtobuf::CreateTableUpdate(const nsACString& aTableName) const
{
return new TableUpdateV4(aTableName);