Bug 284038 OOM crash [@ EnumFonts]

patch by b.jacques@planet.nl r=zack@kde.org a=bsmedberg
This commit is contained in:
timeless%mozdev.org 2005-06-30 20:48:41 +00:00
Родитель 0bf52e2a82
Коммит 7f3f24e713
1 изменённых файлов: 12 добавлений и 1 удалений

Просмотреть файл

@ -287,17 +287,28 @@ NS_IMETHODIMP nsFontMetricsQt::GetFontHandle(nsFontHandle &aHandle)
static nsresult EnumFonts(nsIAtom *aLangGroup,const char *aGeneric,
PRUint32 *aCount,PRUnichar ***aResult)
{
*aResult = nsnull;
*aCount = 0;
/* Get list of all fonts */
QStringList qFamilies = QFontDatabase().families();
int count = qFamilies.count();
PRUnichar **array = (PRUnichar**)nsMemory::Alloc(count * sizeof(PRUnichar*));
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
int i = 0;
for (QStringList::ConstIterator famIt = qFamilies.begin(); famIt != qFamilies.end(); ++famIt) {
QString family = *famIt;
array[i] = new PRUnichar[family.length()];
memcpy(array[i], family.unicode(), family.length()*sizeof(PRUnichar));
if (array[i]) {
memcpy(array[i], family.unicode(), family.length()*sizeof(PRUnichar));
i++;
}
else {
// OOM. Decrease the count and resize the array accordingly.
count--;
array = (PRUnichar**)nsMemory::Realloc((void*)array, count * sizeof(PRUnichar*));
}
}
*aCount = count;