Plug a resource leak in threaded pack-objects code.
A mutex and a condition variable is allocated for each thread and torn down when the thread terminates. However, for certain workloads it can happen that some threads are actually not started at all. In this case we would leak the mutex and condition variable. Now we allocate them only for those threads that are actually started. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Dec 17, 2007 at 20:12 UTC
68e6a4f80d4bea2d281c30fa2bbcd4968b0ccc4e
1 file changed
+2
-2
builtin-pack-objects.c
+2
-2
@@ -1670,8 +1670,6 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
1670
p[i].processed = processed;
1671
p[i].working = 1;
1672
p[i].data_ready = 0;
1673
- pthread_mutex_init(&p[i].mutex, NULL);
1674
- pthread_cond_init(&p[i].cond, NULL);
1673
1674
/* try to split chunks on "path" boundaries */
1675
while (sub_size < list_size && list[sub_size]->hash &&
@@ -1690,6 +1688,8 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
1688
for (i = 0; i < delta_search_threads; i++) {
1689
if (!p[i].list_size)
1690
continue;
1691
+ pthread_mutex_init(&p[i].mutex, NULL);
1692
+ pthread_cond_init(&p[i].cond, NULL);
1693
ret = pthread_create(&p[i].thread, NULL,
1694
threaded_find_deltas, &p[i]);
1695
if (ret)