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

[PATCH 3/5] transport: free filter options in disconnect_git()

From
Jeff King <peff@peff.net>
Date
Sep 8, 2022, 04:58 UTC
Message-ID
<Yxl2Yz8bg9T0dBGo@coredump.intra.peff.net>
In-Reply-To
<Yxl1BNQoy6Drf0Oe@coredump.intra.peff.net>

If a user of the transport API calls transport_set_option() with TRANS_OPT_LIST_OBJECTS_FILTER, it doesn't pass a struct, but rather a string with the filter-spec, which the transport code then stores in its own list_objects_filter_options struct.

When the caller is done and we call transport_disconnect(), the contents of that filter struct are then leaked. We should release it before freeing the transport struct.

Another way to solve this would be for transport_set_option() to pass a pointer to the struct. But that's awkward, because there's a generic transport-option interface that always takes a string. Plus it opens up questions of memory lifetimes; by storing its own filter-options struct, the transport code remains self-contained.

Signed-off-by: Jeff King <peff@peff.net>
---
 transport.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/transport.c b/transport.c
index 24540f642a..6ec6130852 100644
--- a/transport.c
+++ b/transport.c
@@ -895,6 +895,7 @@ static int disconnect_git(struct transport *transport)
 		finish_connect(data->conn);
 	}
 
+	list_objects_filter_release(&data->options.filter_options);
 	free(data);
 	return 0;
 }
-- 
2.37.3.1139.g47294c03c7
Previous: Jeff KingNext: Jeff King
Message 4 of 8 in “plugging some list-objects-filter leaks”
  1. 0/5 plugging some list-objects-filter leaksJeff King, Sep 8, 2022
  2. 1/5 list_objects_filter_copy(): deep-copy sparse_oid_name fieldJeff King, Sep 8, 2022
  3. 2/5 transport: deep-copy object-filter struct for fetch-packJeff King, Sep 8, 2022
  4. 3/5 transport: free filter options in disconnect_git()Jeff King, Sep 8, 2022
  5. 4/5 list_objects_filter_options: plug leak of filter_spec stringsJeff King, Sep 8, 2022
  6. 5/5 prepare_repo_settings(): plug leak of config valuesJeff King, Sep 8, 2022
  7. Derrick StoleeSep 9, 2022
  8. Jeff KingSep 11, 2022

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.