Skip to content

Commit 44e08b0

Browse files
committed
Merge branch 'js/try-to-free-stackable'
* js/try-to-free-stackable: Do not call release_pack_memory in malloc wrappers when GIT_TRACE is used Have set_try_to_free_routine return the previous routine
2 parents 57af58e + 3a09425 commit 44e08b0

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

builtin/pack-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,8 @@ static void try_to_free_from_threads(size_t size)
15291529
read_unlock();
15301530
}
15311531

1532+
try_to_free_t old_try_to_free_routine;
1533+
15321534
/*
15331535
* The main thread waits on the condition that (at least) one of the workers
15341536
* has stopped working (which is indicated in the .working member of
@@ -1563,12 +1565,12 @@ static void init_threaded_search(void)
15631565
pthread_mutex_init(&cache_mutex, NULL);
15641566
pthread_mutex_init(&progress_mutex, NULL);
15651567
pthread_cond_init(&progress_cond, NULL);
1566-
set_try_to_free_routine(try_to_free_from_threads);
1568+
old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
15671569
}
15681570

15691571
static void cleanup_threaded_search(void)
15701572
{
1571-
set_try_to_free_routine(NULL);
1573+
set_try_to_free_routine(old_try_to_free_routine);
15721574
pthread_cond_destroy(&progress_cond);
15731575
pthread_mutex_destroy(&read_mutex);
15741576
pthread_mutex_destroy(&cache_mutex);

git-compat-util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ static inline void *gitmempcpy(void *dest, const void *src, size_t n)
363363

364364
extern void release_pack_memory(size_t, int);
365365

366-
extern void set_try_to_free_routine(void (*routine)(size_t));
366+
typedef void (*try_to_free_t)(size_t);
367+
extern try_to_free_t set_try_to_free_routine(try_to_free_t);
367368

368369
extern char *xstrdup(const char *str);
369370
extern void *xmalloc(size_t size);

trace.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include "cache.h"
2626
#include "quote.h"
2727

28+
void do_nothing(size_t unused)
29+
{
30+
}
31+
2832
/* Get a trace file descriptor from GIT_TRACE env variable. */
2933
static int get_trace_fd(int *need_close)
3034
{
@@ -72,6 +76,7 @@ void trace_printf(const char *fmt, ...)
7276
if (!fd)
7377
return;
7478

79+
set_try_to_free_routine(do_nothing); /* is never reset */
7580
strbuf_init(&buf, 64);
7681
va_start(ap, fmt);
7782
len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
@@ -103,6 +108,7 @@ void trace_argv_printf(const char **argv, const char *fmt, ...)
103108
if (!fd)
104109
return;
105110

111+
set_try_to_free_routine(do_nothing); /* is never reset */
106112
strbuf_init(&buf, 64);
107113
va_start(ap, fmt);
108114
len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);

wrapper.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ static void try_to_free_builtin(size_t size)
1010

1111
static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;
1212

13-
void set_try_to_free_routine(void (*routine)(size_t))
13+
try_to_free_t set_try_to_free_routine(try_to_free_t routine)
1414
{
15-
try_to_free_routine = (routine) ? routine : try_to_free_builtin;
15+
try_to_free_t old = try_to_free_routine;
16+
try_to_free_routine = routine;
17+
return old;
1618
}
1719

1820
char *xstrdup(const char *str)

0 commit comments

Comments
 (0)