git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Plug a resource leak in threaded pack-objects code.

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Dec 17, 2007, 19:12 UTC
Message-ID
<200712172012.52374.johannes.sixt@telecom.at>
In-Reply-To
<476628D1.4020300@viscovery.net>

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>
---
> I just discovered a theoretical resource leakage:
>
> Will send a patch this evening.
Here it is.
-- Hannes
 builtin-pack-objects.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 5765d02..e0ce114 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1670,8 +1670,6 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
 		p[i].processed = processed;
 		p[i].working = 1;
 		p[i].data_ready = 0;
-		pthread_mutex_init(&p[i].mutex, NULL);
-		pthread_cond_init(&p[i].cond, NULL);
 
 		/* try to split chunks on "path" boundaries */
 		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,
 	for (i = 0; i < delta_search_threads; i++) {
 		if (!p[i].list_size)
 			continue;
+		pthread_mutex_init(&p[i].mutex, NULL);
+		pthread_cond_init(&p[i].cond, NULL);
 		ret = pthread_create(&p[i].thread, NULL,
 				     threaded_find_deltas, &p[i]);
 		if (ret)
-- 
1.5.4.rc0.37.g78e7
Previous: Johannes SixtNext: Dmitry Potapov
Message 9 of 11 in “threaded pack-objects: Use condition variables for thread communication.”
  1. threaded pack-objects: Use condition variables for thread communication.Johannes Sixt, Dec 15, 2007
  2. Peter BaumannDec 16, 2007
  3. Johannes SixtDec 16, 2007
  4. Peter BaumannDec 16, 2007
  5. threaded pack-objects: Use condition variables for thread communication.Johannes Sixt, Dec 16, 2007
  6. Junio C HamanoDec 16, 2007
  7. Nicolas PitreDec 17, 2007
  8. Johannes SixtDec 17, 2007
  9. Plug a resource leak in threaded pack-objects code.Johannes Sixt, Dec 17, 2007
  10. Dmitry PotapovDec 17, 2007
  11. David BrownDec 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.