From 7c577863b2b28ea0a7e9accae17bc216c88edc31 Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Tue, 1 Mar 2005 04:29:51 +0000 Subject: [PATCH] Bug 283519 OOM mlk [@ workbuf_extend] patch by ajschult@verizon.net r=timeless sr=roc --- intl/unicharutil/src/nsUnicodeNormalizer.cpp | 27 ++++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/intl/unicharutil/src/nsUnicodeNormalizer.cpp b/intl/unicharutil/src/nsUnicodeNormalizer.cpp index 357081f1e971..fe5573fdff0a 100644 --- a/intl/unicharutil/src/nsUnicodeNormalizer.cpp +++ b/intl/unicharutil/src/nsUnicodeNormalizer.cpp @@ -625,20 +625,25 @@ workbuf_extend(workbuf_t *wb) { if (wb->ucs == wb->ucs_buf) { wb->ucs = (PRUint32*)nsMemory::Alloc(sizeof(wb->ucs[0]) * newsize); + if (!wb->ucs) + return NS_ERROR_OUT_OF_MEMORY; wb->cclass = (PRInt32*)nsMemory::Alloc(sizeof(wb->cclass[0]) * newsize); - } else { - wb->ucs = (PRUint32*)nsMemory::Realloc(wb->ucs, sizeof(wb->ucs[0]) * newsize); - wb->cclass = (PRInt32*)nsMemory::Realloc(wb->cclass, sizeof(wb->cclass[0]) * newsize); - } - if (wb->ucs == NULL || wb->cclass == NULL) { - if (wb->ucs) + if (!wb->cclass) { nsMemory::Free(wb->ucs); - if (wb->cclass) - nsMemory::Free(wb->cclass); - return (NS_ERROR_OUT_OF_MEMORY); + wb->ucs = NULL; + return NS_ERROR_OUT_OF_MEMORY; + } + } else { + void* buf = nsMemory::Realloc(wb->ucs, sizeof(wb->ucs[0]) * newsize); + if (!buf) + return NS_ERROR_OUT_OF_MEMORY; + wb->ucs = (PRUint32*)buf; + buf = nsMemory::Realloc(wb->cclass, sizeof(wb->cclass[0]) * newsize); + if (!buf) + return NS_ERROR_OUT_OF_MEMORY; + wb->cclass = (PRInt32*)buf; } - else - return (NS_OK); + return (NS_OK); } static nsresult