NS_ENSURE_ARG_POINTER(parent_node); NS_ENSURE_ARG_POINTER(child_list);
pcs.bufsize = 2048; pcs.childList = (char*) malloc(sizeof(char) * pcs.bufsize); if (*parent_node > 0) pcs.parent = PR_smprintf("%s.", parent_node); else pcs.parent = PL_strdup(""); if (!pcs.parent || !pcs.childList) return _convertRes(PREF_OUT_OF_MEMORY); pcs.childList[0] = '\0';
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;}