1
0
mirror of https://github.com/adtools/clib2.git synced 2026-05-04 11:29:00 +00:00

- In libunix.a malloc(), calloc() and realloc() no longer treat a

request to allocate 0 bytes as an error, returning NULL. They all
  return a pointer sized memory chunk (= four bytes) initialized to
  NULL (= 0) instead.

- The alloca() implementation which allocates memory from the system
  rather than the local stack frame is thread-safe now. It also
  interacts with the realloc(), calloc(), free() and malloc() functions
  in that the alloca() cleanup routine is called once alloca() has
  done its job. If all the memory allocated through alloca() has been
  released no further calls to the cleanup function will be made.

- In the thread-safe library, realloc() permitted two different overlapping
  calls to succeed in trying to reallocate the same chunk of memory due to
  a race condition. Fixed.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15070 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-11-27 09:26:55 +00:00
parent 06e5f437d9
commit 1153e58366
11 changed files with 90 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
/*
* $Id: stdlib_malloc.c,v 1.16 2005-11-20 19:04:10 obarthel Exp $
* $Id: stdlib_malloc.c,v 1.17 2005-11-27 09:26:55 obarthel Exp $
*
* :ts=4
*
@@ -106,9 +106,9 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in
original_size = size;
/* The libunix.a flavour accepts zero length memory allocations
and quietly turns them into 1 byte allocations. */
and quietly turns them into a pointer sized allocations. */
if(size == 0)
size++;
size = sizeof(char *);
}
#endif /* UNIX_PATH_SEMANTICS */
@@ -210,11 +210,9 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in
#if defined(UNIX_PATH_SEMANTICS)
{
/* Zero length memory allocations in libunix.a quietly
return one byte of memory each, and that byte is
set to '\0'. */
/* Set the zero length allocation contents to NULL. */
if(original_size == 0)
*(char *)result = '\0';
*(char **)result = NULL;
}
#endif /* UNIX_PATH_SEMANTICS */
@@ -245,8 +243,13 @@ __malloc(size_t size,const char * file,int line)
{
void * result = NULL;
__memory_lock();
/* Try to get rid of now unused memory. */
/*__alloca_cleanup(file,line);*/
if(__alloca_cleanup != NULL)
(*__alloca_cleanup)(file,line);
__memory_unlock();
#ifdef __MEM_DEBUG
{