From 71384d8fb5866accf42b695d787899382e315189 Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Thu, 1 Jul 1999 18:39:46 +0000 Subject: [PATCH] Guarding against memory allocation error and a resulting null pointer. Also, now AddRef'ing XPCOM nsPropertyElements when created. --- xpcom/ds/nsProperties.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xpcom/ds/nsProperties.cpp b/xpcom/ds/nsProperties.cpp index 8ac61f6a3e7..918d24ac436 100644 --- a/xpcom/ds/nsProperties.cpp +++ b/xpcom/ds/nsProperties.cpp @@ -362,8 +362,11 @@ AddElemToArray(PLHashEntry* he, PRIntn i, void* arg) nsString* keyStr = new nsString((PRUnichar*) he->key); nsString* valueStr = new nsString((PRUnichar*) he->value); - // XXX Fix to make XPCOM friendly? nsPropertyElement *element = new nsPropertyElement(); + if (!element) + return HT_ENUMERATE_STOP; + + NS_ADDREF(element); element->SetKey(keyStr); element->SetValue(valueStr); propArray->InsertElementAt(element, i); @@ -383,7 +386,9 @@ nsPersistentProperties::EnumerateProperties(nsIBidirectionalEnumerator** aResult return rv; // Step through hash entries populating a transient array - PL_HashTableEnumerateEntries(mTable, AddElemToArray, (void *)propArray); + PRIntn n = PL_HashTableEnumerateEntries(mTable, AddElemToArray, (void *)propArray); + if ( n < (PRIntn) mTable->nentries ) + return NS_ERROR_OUT_OF_MEMORY; // Convert array into enumerator rv = NS_NewISupportsArrayEnumerator(propArray, aResult);