Make xmalloc and xrealloc thread-safe

By providing a hook for the routine responsible for trying to free some
memory on malloc failure, we can ensure that the  called routine is
protected by the appropriate locks when threads are in play.

The obvious offender here was pack-objects which was calling xmalloc()
within threads while release_pack_memory() is not thread safe.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nicolas Pitre
2010-03-24 16:22:34 -04:00
committed by Junio C Hamano
parent 846b8f681a
commit a9a746364b
3 changed files with 27 additions and 4 deletions

View File

@ -346,6 +346,8 @@ static inline char *gitstrchrnul(const char *s, int c)
extern void release_pack_memory(size_t, int);
extern void set_try_to_free_routine(void (*routine)(size_t));
extern char *xstrdup(const char *str);
extern void *xmalloc(size_t size);
extern void *xmallocz(size_t size);