if (prefName == nsnull) { return NS_ERROR_OUT_OF_MEMORY; }  rv = GetChildList(prefName, &theCount, &childArray); if (NS_SUCCEEDED(rv)) {  bufferSize = 2048; childList = (char *)nsMemory::Alloc(sizeof(char) * bufferSize); if (childList != nsnull) { char buf[512]; char* nextdelim; PRUint32 parentlen = PL_strlen(prefName); char* substring;  for (i = 0; i < theCount; ++i) { PL_strncpy(buf, (char *)&childArray[i], PR_MIN(512, PL_strlen((char *)&childArray[i]) + 1)); nextdelim = buf + parentlen; if (parentlen < PL_strlen(buf)) {  nextdelim = PL_strstr(nextdelim, "."); if (nextdelim) { *nextdelim = ';'; *(nextdelim + 1) = '\0'; } }   substring = PL_strstr(childList, buf); if (!substring) { unsigned int newsize = PL_strlen(childList) + PL_strlen(buf) + 2; if (newsize > bufferSize) { bufferSize *= 2; childList = (char *)nsMemory::Realloc(childList, sizeof(char) * bufferSize); if (childList == nsnull) {  break; } } PL_strcat(childList, buf); } } *child_list = childList; }   if (childList == nsnull) { rv = NS_ERROR_OUT_OF_MEMORY; }   NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(theCount, childArray); } PR_Free(prefName);  return rv;
*child_list = pcs.childList; PR_Free(pcs.parent);  return (pcs.childList == NULL) ? PREF_OUT_OF_MEMORY : PREF_OK;
NS_IMETHODIMP nsPref::CreateChildList(const char* parent_node, char **child_list){  PRUint32 bufferSize;  PRUint32 theCount;  PRUint32 i;  nsresult rv;  char     **childArray;  char     *childList;  char     *prefName;  NS_ENSURE_ARG_POINTER(parent_node);  NS_ENSURE_ARG_POINTER(child_list);  if (*parent_node > 0)    prefName = PR_smprintf("%s.", parent_node);  else    prefName = PL_strdup("");  if (prefName == nsnull) {    return NS_ERROR_OUT_OF_MEMORY;  }  rv = GetChildList(prefName, &theCount, &childArray);  if (NS_SUCCEEDED(rv)) {    // now that we've built up the list, build a buffer from the results    bufferSize = 2048;    childList = (char *)nsMemory::Alloc(sizeof(char) * bufferSize);    if (childList != nsnull) {      char buf[512];      char* nextdelim;      PRUint32 parentlen = PL_strlen(prefName);      char* substring;      for (i = 0; i < theCount; ++i) {        PL_strncpy(buf, (char *)&childArray[i], PR_MIN(512, PL_strlen((char *)&childArray[i]) + 1));        nextdelim = buf + parentlen;        if (parentlen < PL_strlen(buf)) {          // Find the next delimiter if any and truncate the string there          nextdelim = PL_strstr(nextdelim, ".");          if (nextdelim) {            *nextdelim = ';';            *(nextdelim + 1) = '\0';          }        }        // if this substring isn't already in the buffer, add it        substring = PL_strstr(childList, buf);        if (!substring) {          unsigned int newsize = PL_strlen(childList) + PL_strlen(buf) + 2;          if (newsize > bufferSize) {            bufferSize *= 2;            childList = (char *)nsMemory::Realloc(childList, sizeof(char) * bufferSize);            if (childList == nsnull) {              // problem... break out of for loop              break;            }          }          PL_strcat(childList, buf);        }      }      *child_list = childList;    }    // if we had an Alloc or Realloc problem    if (childList == nsnull) {      rv = NS_ERROR_OUT_OF_MEMORY;    }    // release the memory allocated by GetChildList    NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(theCount, childArray);  }  PR_Free(prefName);  return rv;}