// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a simple allocator based on the windows heap.

extern "C" {

HANDLE win_heap;

bool win_heap_init(bool use_lfh) {
  win_heap = HeapCreate(0, 0, 0);
  if (win_heap == NULL)
    return false;

  if (use_lfh) {
    ULONG enable_lfh = 2;
    HeapSetInformation(win_heap, HeapCompatibilityInformation,
                       &enable_lfh, sizeof(enable_lfh));
    // NOTE: Setting LFH may fail.  Vista already has it enabled.
    //       And under the debugger, it won't use LFH.  So we
    //       ignore any errors.
  }

  return true;
}

void* win_heap_malloc(size_t size) {
  return HeapAlloc(win_heap, 0, size);
}

void win_heap_free(void* size) {
  HeapFree(win_heap, 0, size);
}

void* win_heap_realloc(void* ptr, size_t size) {
  if (!ptr)
    return win_heap_malloc(size);
  if (!size) {
    win_heap_free(ptr);
    return NULL;
  }
  return HeapReAlloc(win_heap, 0, ptr, size);
}

size_t win_heap_msize(void* ptr) {
  return HeapSize(win_heap, 0, ptr);
}

}  // extern "C"

// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a simple allocator based on the windows heap.

extern "C" {

HANDLE win_heap;

bool win_heap_init(bool use_lfh) {
  win_heap = HeapCreate(0, 0, 0);
  if (win_heap == NULL)
    return false;

  if (use_lfh) {
    ULONG enable_lfh = 2;
    HeapSetInformation(win_heap, HeapCompatibilityInformation,
                       &enable_lfh, sizeof(enable_lfh));
    // NOTE: Setting LFH may fail.  Vista already has it enabled.
    //       And under the debugger, it won't use LFH.  So we
    //       ignore any errors.
  }

  return true;
}

void* win_heap_malloc(size_t s) {
  return HeapAlloc(win_heap, 0, s);
}

void* win_heap_realloc(void* p, size_t s) {
  if (!p)
    return win_heap_malloc(s);
  return HeapReAlloc(win_heap, 0, p, s);
}

void win_heap_free(void* s) {
  HeapFree(win_heap, 0, s);
}

size_t win_heap_msize(void* p) {
  return HeapSize(win_heap, 0, p);
}

}  // extern "C"

--- 
+++ 
@@ -25,22 +25,26 @@
   return true;
 }
 
-void* win_heap_malloc(size_t s) {
-  return HeapAlloc(win_heap, 0, s);
+void* win_heap_malloc(size_t size) {
+  return HeapAlloc(win_heap, 0, size);
 }
 
-void* win_heap_realloc(void* p, size_t s) {
-  if (!p)
-    return win_heap_malloc(s);
-  return HeapReAlloc(win_heap, 0, p, s);
+void win_heap_free(void* size) {
+  HeapFree(win_heap, 0, size);
 }
 
-void win_heap_free(void* s) {
-  HeapFree(win_heap, 0, s);
+void* win_heap_realloc(void* ptr, size_t size) {
+  if (!ptr)
+    return win_heap_malloc(size);
+  if (!size) {
+    win_heap_free(ptr);
+    return NULL;
+  }
+  return HeapReAlloc(win_heap, 0, ptr, size);
 }
 
-size_t win_heap_msize(void* p) {
-  return HeapSize(win_heap, 0, p);
+size_t win_heap_msize(void* ptr) {
+  return HeapSize(win_heap, 0, ptr);
 }
 
 }  // extern "C"
Fix the windows allocator to behave properly on realloc.

The spec says that calling realloc(ptr, 0) should free ptr
and return NULL.


BUG=none
TEST=none

Review URL: http://codereview.chromium.org/196041

git-svn-id: http://src.chromium.org/svn/trunk/src@25612 4ff67af0-8c30-449e-8e8b-ad334ec8d88c

Former-commit-id: fae861b25df7e99d1b1e17265d613e32e19b79da