Bug 916580 - Fix bugs related to the usage of calloc. r=luke, a=bajaj
authorDan Gohman <sunfish@google.com>
Fri, 18 Oct 2013 09:22:52 -0400
changeset 119952 53542d252c2dffa1d725a87c624d085c88c607a2
parent 119951 7fedb6a967eabeafc58fff4efcdff624a9af77ef
child 119953 8ab36ae7129b6d15563cca8d22efd7004238425c
push id1091
push userryanvm@gmail.com
push dateFri, 18 Oct 2013 13:23:03 +0000
reviewersluke, bajaj
bugs916580
milestone18.1
Bug 916580 - Fix bugs related to the usage of calloc. r=luke, a=bajaj
js/jsd/jsd_lock.cpp
js/public/Utility.h
js/src/jsutil.cpp
--- a/js/jsd/jsd_lock.cpp
+++ b/js/jsd/jsd_lock.cpp
@@ -79,17 +79,17 @@ void ASSERT_VALID_LOCK(JSDStaticLock* lo
 #define ASSERT_VALID_LOCK(x) ((void)0)
 #endif
 
 JSDStaticLock*
 jsd_CreateLock()
 {
     JSDStaticLock* lock;
 
-    if( ! (lock = js_pod_calloc<JSDStaticLock>(1)) ||
+    if( ! (lock = js_pod_calloc<JSDStaticLock>()) ||
         ! (lock->lock = PR_NewLock()) )
     {
         if(lock)
         {
             free(lock);
             lock = NULL;
         }
     }
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -154,16 +154,22 @@ static JS_INLINE void* js_malloc(size_t 
 }
 
 static JS_INLINE void* js_calloc(size_t bytes)
 {
     JS_OOM_POSSIBLY_FAIL();
     return calloc(bytes, 1);
 }
 
+static JS_INLINE void* js_calloc_members(size_t nmemb, size_t size)
+{
+    JS_OOM_POSSIBLY_FAIL();
+    return calloc(nmemb, size);
+}
+
 static JS_INLINE void* js_realloc(void* p, size_t bytes)
 {
     JS_OOM_POSSIBLY_FAIL();
     return realloc(p, bytes);
 }
 
 static JS_INLINE void js_free(void* p)
 {
--- a/js/src/jsutil.cpp
+++ b/js/src/jsutil.cpp
@@ -28,17 +28,17 @@
 #endif
 
 using namespace js;
 
 #if USE_ZLIB
 static void *
 zlib_alloc(void *cx, uInt items, uInt size)
 {
-    return js_malloc(items * size);
+    return js_calloc_members(items, size);
 }
 
 static void
 zlib_free(void *cx, void *addr)
 {
     js_free(addr);
 }