[PATCH] introduce xmalloc and xrealloc
Introduce xmalloc and xrealloc to die gracefully with a descriptive message when out of memory, rather than taking a SIGSEGV. Signed-off-by: Christopher Li<chrislgit@chrisli.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
committed by
Linus Torvalds
parent
f2a19340ad
commit
812666c8e6
4
object.c
4
object.c
@ -52,7 +52,7 @@ void created_object(unsigned char *sha1, struct object *obj)
|
||||
|
||||
if (obj_allocs == nr_objs) {
|
||||
obj_allocs = alloc_nr(obj_allocs);
|
||||
objs = realloc(objs, obj_allocs * sizeof(struct object *));
|
||||
objs = xrealloc(objs, obj_allocs * sizeof(struct object *));
|
||||
}
|
||||
|
||||
/* Insert it into the right place */
|
||||
@ -75,7 +75,7 @@ void add_ref(struct object *refer, struct object *target)
|
||||
}
|
||||
|
||||
target->used = 1;
|
||||
p = malloc(sizeof(*p));
|
||||
p = xmalloc(sizeof(*p));
|
||||
p->item = target;
|
||||
p->next = NULL;
|
||||
*pp = p;
|
||||
|
||||
Reference in New Issue
Block a user