diff options
author | Jeremy Allison <jra@samba.org> | 2001-10-22 02:34:41 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-10-22 02:34:41 +0000 |
commit | 96ef1b0eb2d408a4ac9f7cc1b7c1bfe53252715d (patch) | |
tree | 6d389de0bad948e21c621d68cee0d800c3775aa1 /source3/lib | |
parent | cfd68eaac48a29dec245dc6de03aae0d58698862 (diff) | |
download | samba-96ef1b0eb2d408a4ac9f7cc1b7c1bfe53252715d.tar.gz samba-96ef1b0eb2d408a4ac9f7cc1b7c1bfe53252715d.tar.bz2 samba-96ef1b0eb2d408a4ac9f7cc1b7c1bfe53252715d.zip |
Added xmalloc - calls smb_panic on zero size or malloc fail.
Added xmemdup - calls xmalloc.
Made data_blob() call xmemdup.
Defensive programming (I still hate the no error checking... :-).
Jeremy.
(This used to be commit 2cc262278f9d4892cf2485d7a73d88bc0e7559a8)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/util.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index d3f07dd0a8..cd170ff3d3 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1642,6 +1642,32 @@ int smb_mkstemp(char *template) } /***************************************************************** + malloc that aborts with smb_panic on fail or zero size. + *****************************************************************/ + +void *xmalloc(size_t size) +{ + void *p; + if (size == 0) + smb_panic("xmalloc called with zero size.\n"); + if ((p = malloc(size)) == NULL) + smb_panic("xmalloc malloc fail.\n"); + return p; +} + +/***************************************************************** + Memdup with smb_panic on fail. + *****************************************************************/ + +void *xmemdup(void *p, size_t size) +{ + void *p2; + p2 = xmalloc(size); + memcpy(p2, p, size); + return p2; +} + +/***************************************************************** like strdup but for memory *****************************************************************/ void *memdup(void *p, size_t size) @@ -1905,7 +1931,7 @@ DATA_BLOB data_blob(void *p, size_t length) return ret; } - ret.data = memdup(p, length); + ret.data = xmemdup(p, length); ret.length = length; return ret; } |