mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
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 commit is contained in:
parent
b668d7d656
commit
2cc262278f
@ -1641,6 +1641,32 @@ int smb_mkstemp(char *template)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
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
|
||||
*****************************************************************/
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user