node->name = name.ToNewUnicode();
node->name = ToNewUnicode(name);
static nsresult EnumFonts(nsIAtom *aLangGroup,const char *aGeneric,                          PRUint32 *aCount,PRUnichar ***aResult){  QFontDatabase *qFontDB = nsFontMetricsQT::GetQFontDB();  QStringList qCharsets,qFamilies;  FontEnumNode *head = nsnull,*tail = nsnull;  int count = 0;  /* Get list of all fonts */  qFamilies = qFontDB->families(FALSE);  qFamilies.sort();  for (QStringList::Iterator famIt = qFamilies.begin();       famIt != qFamilies.end(); ++famIt) {    qCharsets = qFontDB->charSets(*famIt,FALSE);    qCharsets.sort();    for (QStringList::Iterator csIt = qCharsets.begin();         csIt != qCharsets.end(); ++csIt) {      nsCStringKey charSetKey((*csIt).latin1());       nsFontCharSetInfo *charSetInfo       = (nsFontCharSetInfo*)gCharSets->Get(&charSetKey);      // indirection for font specific charset encoding      if (charSetInfo == &Special) {        nsCAutoString familyCharSetName((*famIt).latin1());        familyCharSetName.Append('-');        familyCharSetName.Append((*csIt).latin1());        nsCStringKey familyCharSetKey(familyCharSetName);        charSetInfo          = (nsFontCharSetInfo*)gSpecialCharSets->Get(&familyCharSetKey);      }      if (!charSetInfo) {        continue;      }      if (aLangGroup != gUserDefined && charSetInfo == &Unknown) {        continue;      }      if (aLangGroup != gUnicode) {        nsresult res;        if (!charSetInfo->mCharsetAtom) {          res = gCharSetManager->GetCharsetAtom2(charSetInfo->mCharSet,                                                 &charSetInfo->mCharsetAtom);          if (NS_FAILED(res)) {            continue;          }        }        if (!charSetInfo->mLangGroup) {          res = gCharSetManager->GetCharsetLangGroup(charSetInfo->mCharsetAtom,                                                     &charSetInfo->mLangGroup);          if (NS_FAILED(res)) {            continue;          }        }        if (aLangGroup != charSetInfo->mLangGroup) {          continue;        }      }      nsCAutoString name((*famIt).latin1());      FontEnumNode *node = (FontEnumNode*)nsMemory::Alloc(sizeof(FontEnumNode));      if (!node) {        FontEnumNode *ptr = head,*tmp;        while (ptr) {          tmp = ptr;          nsMemory::Free(ptr->name);          ptr = ptr->next;          nsMemory::Free(tmp);        }        return NS_ERROR_OUT_OF_MEMORY;      }      node->name = name.ToNewUnicode();      if (!node->name) {        FontEnumNode *ptr = head,*tmp;        while (ptr) {          tmp = ptr;          nsMemory::Free(ptr->name);          ptr = ptr->next;          nsMemory::Free(tmp);        }        return NS_ERROR_OUT_OF_MEMORY;      }      node->next = nsnull;      if (!head) {        head = node;      }      else {        tail->next = node;      }      tail = node;      count++;    }  }  PRUnichar **array = (PRUnichar**)nsMemory::Alloc(count * sizeof(PRUnichar*));  if (!array) {    FontEnumNode *ptr = head,*tmp;    while (ptr) {      tmp = ptr;      nsMemory::Free(ptr->name);      ptr = ptr->next;      nsMemory::Free(tmp);    }    return NS_ERROR_OUT_OF_MEMORY;  }  FontEnumNode *ptr = head,*tmp;  for (int i = 0; i < count; i++) {    tmp = ptr;    array[i] = ptr->name;    ptr = ptr->next;    nsMemory::Free(tmp);  }  NS_QuickSort(array,count,sizeof(PRUnichar*),CompareFontNames,nsnull);   *aCount = count;  *aResult = array;  return NS_OK;}