mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1172761 (part 2) - Remove PL_DHashTableEnumerator use from nsPersistentProperties. r=froydnj.
The old code attempted to deal with any OOMs during this enumeration -- OOMs are possible because it's growing an nsCOMArray -- but failed to do so correctly. - It didn't check the return value of AppendObject(). - It did check that EntryCount() matched the return value of PL_DHashTableEnumerate(), but that's always (and vacuously) true. The new code just returns NS_ERROR_OUT_OF_MEMORY if AppendObject() fails; this is trivial now that it uses an iterator and doesn't have to call out to another function.
This commit is contained in:
parent
bb0c06fd91
commit
06bec04d53
@ -563,25 +563,6 @@ nsPersistentProperties::GetStringProperty(const nsACString& aKey,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
AddElemToArray(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
|
||||
uint32_t aIndex, void* aArg)
|
||||
{
|
||||
nsCOMArray<nsIPropertyElement>* props =
|
||||
static_cast<nsCOMArray<nsIPropertyElement>*>(aArg);
|
||||
PropertyTableEntry* entry =
|
||||
static_cast<PropertyTableEntry*>(aHdr);
|
||||
|
||||
nsPropertyElement* element =
|
||||
new nsPropertyElement(nsDependentCString(entry->mKey),
|
||||
nsDependentString(entry->mValue));
|
||||
|
||||
props->AppendObject(element);
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::Enumerate(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
@ -591,9 +572,17 @@ nsPersistentProperties::Enumerate(nsISimpleEnumerator** aResult)
|
||||
props.SetCapacity(mTable.EntryCount());
|
||||
|
||||
// Step through hash entries populating a transient array
|
||||
uint32_t n = PL_DHashTableEnumerate(&mTable, AddElemToArray, (void*)&props);
|
||||
if (n < mTable.EntryCount()) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
PLDHashTable::Iterator iter(&mTable);
|
||||
while (iter.HasMoreEntries()) {
|
||||
auto entry = static_cast<PropertyTableEntry*>(iter.NextEntry());
|
||||
|
||||
nsRefPtr<nsPropertyElement> element =
|
||||
new nsPropertyElement(nsDependentCString(entry->mKey),
|
||||
nsDependentString(entry->mValue));
|
||||
|
||||
if (!props.AppendObject(element)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_NewArrayEnumerator(aResult, props);
|
||||
|
Loading…
Reference in New Issue
Block a user