зеркало из https://github.com/mozilla/gecko-dev.git
Bug 284038 OOM crash [@ EnumFonts]
patch by b.jacques@planet.nl r=zack@kde.org a=bsmedberg
This commit is contained in:
Родитель
0bf52e2a82
Коммит
7f3f24e713
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче