summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-05-31 10:42:30 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-05-31 02:57:19 +0200
commit8c8ff2cd6b597f7c4759cfaf178857ac533cc9ba (patch)
treebdd1e0992f5474a6a37b16eaa6cc2d603ab7f6bf /source3/lib/util.c
parent52399f3177515fce777d85288650ff89f9028dc9 (diff)
downloadsamba-8c8ff2cd6b597f7c4759cfaf178857ac533cc9ba.tar.gz
samba-8c8ff2cd6b597f7c4759cfaf178857ac533cc9ba.tar.bz2
samba-8c8ff2cd6b597f7c4759cfaf178857ac533cc9ba.zip
s3-lib Move source3-specific malloc replacements into a seperate file
This will make it easier to create a dep tree for otherwise simple libraries. Andrew Bartlett
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c143
1 files changed, 0 insertions, 143 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index f86f51790f..173e9067cc 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -430,149 +430,6 @@ NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
return status;
}
-#if defined(PARANOID_MALLOC_CHECKER)
-
-/****************************************************************************
- Internal malloc wrapper. Externally visible.
-****************************************************************************/
-
-void *malloc_(size_t size)
-{
- if (size == 0) {
- return NULL;
- }
-#undef malloc
- return malloc(size);
-#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
-}
-
-/****************************************************************************
- Internal calloc wrapper. Not externally visible.
-****************************************************************************/
-
-static void *calloc_(size_t count, size_t size)
-{
- if (size == 0 || count == 0) {
- return NULL;
- }
-#undef calloc
- return calloc(count, size);
-#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY
-}
-
-/****************************************************************************
- Internal realloc wrapper. Not externally visible.
-****************************************************************************/
-
-static void *realloc_(void *ptr, size_t size)
-{
-#undef realloc
- return realloc(ptr, size);
-#define realloc(p,s) __ERROR_DONT_USE_RELLOC_DIRECTLY
-}
-
-#endif /* PARANOID_MALLOC_CHECKER */
-
-/****************************************************************************
- Type-safe memalign
-****************************************************************************/
-
-void *memalign_array(size_t el_size, size_t align, unsigned int count)
-{
- if (count >= MAX_ALLOC_SIZE/el_size) {
- return NULL;
- }
-
- return sys_memalign(align, el_size*count);
-}
-
-/****************************************************************************
- Type-safe calloc.
-****************************************************************************/
-
-void *calloc_array(size_t size, size_t nmemb)
-{
- if (nmemb >= MAX_ALLOC_SIZE/size) {
- return NULL;
- }
- if (size == 0 || nmemb == 0) {
- return NULL;
- }
-#if defined(PARANOID_MALLOC_CHECKER)
- return calloc_(nmemb, size);
-#else
- return calloc(nmemb, size);
-#endif
-}
-
-/****************************************************************************
- Expand a pointer to be a particular size.
- Note that this version of Realloc has an extra parameter that decides
- whether to free the passed in storage on allocation failure or if the
- new size is zero.
-
- This is designed for use in the typical idiom of :
-
- p = SMB_REALLOC(p, size)
- if (!p) {
- return error;
- }
-
- and not to have to keep track of the old 'p' contents to free later, nor
- to worry if the size parameter was zero. In the case where NULL is returned
- we guarentee that p has been freed.
-
- If free later semantics are desired, then pass 'free_old_on_error' as False which
- guarentees that the old contents are not freed on error, even if size == 0. To use
- this idiom use :
-
- tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size);
- if (!tmp) {
- SAFE_FREE(p);
- return error;
- } else {
- p = tmp;
- }
-
- Changes were instigated by Coverity error checking. JRA.
-****************************************************************************/
-
-void *Realloc(void *p, size_t size, bool free_old_on_error)
-{
- void *ret=NULL;
-
- if (size == 0) {
- if (free_old_on_error) {
- SAFE_FREE(p);
- }
- DEBUG(2,("Realloc asked for 0 bytes\n"));
- return NULL;
- }
-
-#if defined(PARANOID_MALLOC_CHECKER)
- if (!p) {
- ret = (void *)malloc_(size);
- } else {
- ret = (void *)realloc_(p,size);
- }
-#else
- if (!p) {
- ret = (void *)malloc(size);
- } else {
- ret = (void *)realloc(p,size);
- }
-#endif
-
- if (!ret) {
- if (free_old_on_error && p) {
- SAFE_FREE(p);
- }
- DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
- }
-
- return(ret);
-}
-
/****************************************************************************
(Hopefully) efficient array append.
****************************************************************************/