Use xmalloc() instead of malloc() in the places where malloc() calls
are assumed to not fail. Make the xcalloc() calling conventions follow the calloc(3) calling conventions and replace unchecked calls to calloc() with calls to xcalloc(). Remove redundand declarations from xmalloc.c, which are already present in rtld.h. Reviewed by: kan Discussed with: bde MFC after: 2 weeks
This commit is contained in:
parent
348388ff1c
commit
625402758b
@ -87,7 +87,7 @@ alloc_fptr(Elf_Addr target, Elf_Addr gp)
|
||||
struct fptr* fptr;
|
||||
|
||||
if (next_fptr == last_fptr) {
|
||||
current_chunk = malloc(sizeof(struct fptr_chunk));
|
||||
current_chunk = xmalloc(sizeof(struct fptr_chunk));
|
||||
next_fptr = ¤t_chunk->fptrs[0];
|
||||
last_fptr = ¤t_chunk->fptrs[FPTR_CHUNK_SIZE];
|
||||
}
|
||||
@ -116,9 +116,7 @@ alloc_fptrs(Obj_Entry *obj, bool mapped)
|
||||
if (fptrs == MAP_FAILED)
|
||||
fptrs = NULL;
|
||||
} else {
|
||||
fptrs = malloc(fbytes);
|
||||
if (fptrs != NULL)
|
||||
memset(fptrs, 0, fbytes);
|
||||
fptrs = xcalloc(1, fbytes);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -338,7 +338,7 @@ reloc_plt_object(Obj_Entry *obj, const Elf_Rela *rela)
|
||||
reloff = rela - obj->pltrela;
|
||||
|
||||
if (obj->priv == NULL)
|
||||
obj->priv = malloc(obj->pltrelasize);
|
||||
obj->priv = xmalloc(obj->pltrelasize);
|
||||
glink = obj->priv + reloff*sizeof(Elf_Addr)*2;
|
||||
|
||||
dbg(" reloc_plt_object: where=%p,reloff=%lx,glink=%p", (void *)where, reloff, glink);
|
||||
|
@ -3733,7 +3733,7 @@ tls_get_addr_slow(Elf_Addr **dtvp, int index, size_t offset)
|
||||
/* Check dtv generation in case new modules have arrived */
|
||||
if (dtv[0] != tls_dtv_generation) {
|
||||
wlock_acquire(rtld_bind_lock, &lockstate);
|
||||
newdtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
|
||||
newdtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
|
||||
to_copy = dtv[1];
|
||||
if (to_copy > tls_max_index)
|
||||
to_copy = tls_max_index;
|
||||
@ -3788,7 +3788,7 @@ allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign)
|
||||
return (oldtcb);
|
||||
|
||||
assert(tcbsize >= TLS_TCB_SIZE);
|
||||
tcb = calloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize);
|
||||
tcb = xcalloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize);
|
||||
tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE);
|
||||
|
||||
if (oldtcb != NULL) {
|
||||
@ -3804,7 +3804,7 @@ allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dtv = calloc(tls_max_index + 2, sizeof(Elf_Addr));
|
||||
dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
|
||||
tls[0] = dtv;
|
||||
dtv[0] = tls_dtv_generation;
|
||||
dtv[1] = tls_max_index;
|
||||
@ -3868,8 +3868,8 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign)
|
||||
size = round(tls_static_space, tcbalign);
|
||||
|
||||
assert(tcbsize >= 2*sizeof(Elf_Addr));
|
||||
tls = calloc(1, size + tcbsize);
|
||||
dtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
|
||||
tls = xcalloc(1, size + tcbsize);
|
||||
dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
|
||||
|
||||
segbase = (Elf_Addr)(tls + size);
|
||||
((Elf_Addr*)segbase)[0] = segbase;
|
||||
@ -4209,7 +4209,7 @@ rtld_verify_object_versions(Obj_Entry *obj)
|
||||
* way.
|
||||
*/
|
||||
obj->vernum = maxvernum + 1;
|
||||
obj->vertab = calloc(obj->vernum, sizeof(Ver_Entry));
|
||||
obj->vertab = xcalloc(obj->vernum, sizeof(Ver_Entry));
|
||||
|
||||
vd = obj->verdef;
|
||||
while (vd != NULL) {
|
||||
|
@ -58,7 +58,7 @@
|
||||
#endif
|
||||
|
||||
#define NEW(type) ((type *) xmalloc(sizeof(type)))
|
||||
#define CNEW(type) ((type *) xcalloc(sizeof(type)))
|
||||
#define CNEW(type) ((type *) xcalloc(1, sizeof(type)))
|
||||
|
||||
/* We might as well do booleans like C++. */
|
||||
typedef unsigned char bool;
|
||||
@ -319,7 +319,7 @@ typedef struct Struct_SymLook {
|
||||
extern void _rtld_error(const char *, ...) __printflike(1, 2);
|
||||
extern const char *rtld_strerror(int);
|
||||
extern Obj_Entry *map_object(int, const char *, const struct stat *);
|
||||
extern void *xcalloc(size_t);
|
||||
extern void *xcalloc(size_t, size_t);
|
||||
extern void *xmalloc(size_t);
|
||||
extern char *xstrdup(const char *);
|
||||
extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
|
||||
|
@ -32,14 +32,17 @@
|
||||
#include "rtld.h"
|
||||
#include "rtld_printf.h"
|
||||
|
||||
void *xcalloc(size_t);
|
||||
void *xmalloc(size_t);
|
||||
char *xstrdup(const char *);
|
||||
|
||||
void *
|
||||
xcalloc(size_t size)
|
||||
xcalloc(size_t number, size_t size)
|
||||
{
|
||||
return memset(xmalloc(size), 0, size);
|
||||
void *p;
|
||||
|
||||
p = calloc(number, size);
|
||||
if (p == NULL) {
|
||||
rtld_fdputstr(STDERR_FILENO, "Out of memory\n");
|
||||
_exit(1);
|
||||
}
|
||||
return (p);
|
||||
}
|
||||
|
||||
void *
|
||||
|
Loading…
Reference in New Issue
Block a user