Maybe we should add free to realloc and expand
to avoid memmory leak ??
I know realloc fail in windows it can create memory leak
text from internet how malloc should work
" If the size of the space requested is 0, the behavior is
implementation-defined:
the value returned shall be either a null pointer or a unique pointer."
But most devloper assume malloc will return NULL if size is 0
But some windows platfroms it return vaild pointer.
The question is how should we handle it in reactos,
return NULL or vaild pointer for this case ?
----- Original Message -----
From: "Thomas Weidenmueller" <w3seek(a)reactos.com>
To: "ReactOS Development List" <ros-dev(a)reactos.org>
Sent: Saturday, June 03, 2006 4:39 PM
Subject: Re: [ros-dev] [ros-diffs] [greatlrd] 22195: make malloc, calloc and
some other function return NULL if size is 0
Royce Mitchell III wrote:
@@ -60,6
+66,9 @@
*/
void* realloc(void* _ptr, size_t _size)
{
+ if ( _size == 0)
+ return NULL;
+
if (!_ptr) return malloc(_size);
if (_size) return HeapReAlloc(hHeap, 0, _ptr, ROUND_SIZE(_size));
free(_ptr);
@@ -71,6 +80,9 @@
*/
umm... shouldn't we call free() if we're going to return NULL because
size is 0?
realloc never frees the memory if it fails.
Also, the free() at the bottom is never called
now.
it's wrong and shouldn't even be there ;)
>> void* _expand(void* _ptr, size_t _size)
>> {
>> + if ( _size == 0)
>> + return NULL;
>> +
>> return HeapReAlloc(hHeap, HEAP_REALLOC_IN_PLACE_ONLY, _ptr,
}
Again, shouldn't we free the existing buffer if we're returning NULL
because size is 0?
no, same as with realloc.
- Thomas
_______________________________________________
Ros-dev mailing list
Ros-dev(a)reactos.org
http://www.reactos.org/mailman/listinfo/ros-dev