[PATCH v5 1/3] transport: add `transport_options_release()`
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Oct 28, 2026, 09:47 UTC
- Message-ID
- <20261028-799-shallow-fetch-with-tags-v5-1-7c43cc9ae810@gmail.com>
- In-Reply-To
- <20261028-799-shallow-fetch-with-tags-v5-0-7c43cc9ae810@gmail.com>
The `git_transport_options` structure is used both in 'transport.c' and 'transport-helper.c'. But while the former specifically clears any associated data in the structure during the cleanup of the transport, the latter misses this.
This means when using remote-helpers, data allocated for the structure leaks. Introduce a new `transport_options_release()`, which acts as a common path to release memory allocated with the structure and use it in both files.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com> --- transport-helper.c | 1 + transport.c | 24 ++++++++++++++---------- transport.h | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/transport-helper.c b/transport-helper.c index d5a064d386..14d179e0f6 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -401,6 +401,7 @@ static int release_helper(struct transport *transport) refspec_clear(&data->rs); free(data->import_marks); free(data->export_marks); + transport_options_release(&data->transport_options); res = disconnect_helper(transport); free(transport->data); return res; diff --git a/transport.c b/transport.c index 25e2c14a7b..4491443b28 100644 --- a/transport.c +++ b/transport.c @@ -1017,6 +1017,19 @@ static int connect_git(struct transport *transport, return 0; } +void transport_options_release(struct git_transport_options *options) +{ + if (options->negotiation_restrict_tips) { + oid_array_clear(options->negotiation_restrict_tips); + free(options->negotiation_restrict_tips); + } + if (options->negotiation_include_tips) { + oid_array_clear(options->negotiation_include_tips); + free(options->negotiation_include_tips); + } + list_objects_filter_release(&options->filter_options); +} + static int disconnect_git(struct transport *transport) { struct git_transport_data *data = transport->data; @@ -1028,16 +1041,7 @@ static int disconnect_git(struct transport *transport) close(data->fd[1]); finish_connect(data->conn); } - - if (data->options.negotiation_restrict_tips) { - oid_array_clear(data->options.negotiation_restrict_tips); - free(data->options.negotiation_restrict_tips); - } - if (data->options.negotiation_include_tips) { - oid_array_clear(data->options.negotiation_include_tips); - free(data->options.negotiation_include_tips); - } - list_objects_filter_release(&data->options.filter_options); + transport_options_release(&data->options); oid_array_clear(&data->extra_have); oid_array_clear(&data->shallow); free(data); diff --git a/transport.h b/transport.h index 39193d0077..cb262ee3da 100644 --- a/transport.h +++ b/transport.h @@ -59,6 +59,8 @@ struct git_transport_options { struct oidset *acked_commits; }; +void transport_options_release(struct git_transport_options *options); + enum transport_family { TRANSPORT_FAMILY_ALL = 0, TRANSPORT_FAMILY_IPV4,
-- 2.56.GIT