aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-10-02 07:46:26 -0700
committerJunio C Hamano <gitster@pobox.com>2024-10-02 07:46:26 -0700
commit59ee4f70136a12feb47979ca90baaf7c7beafe73 (patch)
tree06d69eaa4a69f974b284f6a71df1fbb8319d0144
parent365529e1ea19b44a7a253b780f3ae3a1cb2f081f (diff)
parentf4c768c639566da07fc063fa9b52607f54ac94ee (diff)
downloadgit-59ee4f70136a12feb47979ca90baaf7c7beafe73.tar.gz
Merge branch 'jk/http-leakfixes'
Leakfixes. * jk/http-leakfixes: (28 commits) http-push: clean up local_refs at exit http-push: clean up loose request when falling back to packed http-push: clean up objects list http-push: free xml_ctx.cdata after use http-push: free remote_ls_ctx.dentry_name http-push: free transfer_request strbuf http-push: free transfer_request dest field http-push: free curl header lists http-push: free repo->url string http-push: clear refspecs before exiting http-walker: free fake packed_git list remote-curl: free HEAD ref with free_one_ref() http: stop leaking buffer in http_get_info_packs() http: call git_inflate_end() when releasing http_object_request http: fix leak of http_object_request struct http: fix leak when redacting cookies from curl trace transport-helper: fix leak of dummy refs_list fetch-pack: clear pack lockfiles list fetch: free "raw" string when shrinking refspec transport-helper: fix strbuf leak in push_refs_with_push() ...
-rw-r--r--builtin/fetch-pack.c14
-rw-r--r--builtin/fetch.c1
-rw-r--r--builtin/push.c1
-rw-r--r--builtin/send-pack.c2
-rw-r--r--commit.c3
-rw-r--r--connect.c1
-rw-r--r--http-fetch.c16
-rw-r--r--http-push.c40
-rw-r--r--http-walker.c18
-rw-r--r--http.c16
-rw-r--r--http.h4
-rw-r--r--refspec.c2
-rw-r--r--refspec.h2
-rw-r--r--remote-curl.c2
-rw-r--r--remote.c2
-rw-r--r--remote.h1
-rw-r--r--shallow.c5
-rwxr-xr-xt/t5500-fetch-pack.sh1
-rwxr-xr-xt/t5539-fetch-http-shallow.sh1
-rwxr-xr-xt/t5540-http-push-webdav.sh1
-rwxr-xr-xt/t5541-http-push-smart.sh1
-rwxr-xr-xt/t5542-push-http-shallow.sh1
-rwxr-xr-xt/t5550-http-fetch-dumb.sh1
-rwxr-xr-xt/t5551-http-fetch-smart.sh1
-rwxr-xr-xt/t5582-fetch-negative-refspec.sh1
-rwxr-xr-xt/t5619-clone-local-ambiguous-transport.sh1
-rwxr-xr-xt/t5700-protocol-v1.sh1
-rw-r--r--transport-helper.c11
-rw-r--r--transport.c11
29 files changed, 123 insertions, 39 deletions
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 49222a36fa..62e8c3aa6b 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -53,6 +53,7 @@ int cmd_fetch_pack(int argc,
struct ref *fetched_refs = NULL, *remote_refs = NULL;
const char *dest = NULL;
struct ref **sought = NULL;
+ struct ref **sought_to_free = NULL;
int nr_sought = 0, alloc_sought = 0;
int fd[2];
struct string_list pack_lockfiles = STRING_LIST_INIT_DUP;
@@ -243,6 +244,13 @@ int cmd_fetch_pack(int argc,
BUG("unknown protocol version");
}
+ /*
+ * Create a shallow copy of `sought` so that we can free all of its entries.
+ * This is because `fetch_pack()` will modify the array to evict some
+ * entries, but won't free those.
+ */
+ DUP_ARRAY(sought_to_free, sought, nr_sought);
+
fetched_refs = fetch_pack(&args, fd, remote_refs, sought, nr_sought,
&shallow, pack_lockfiles_ptr, version);
@@ -280,9 +288,13 @@ int cmd_fetch_pack(int argc,
oid_to_hex(&ref->old_oid), ref->name);
for (size_t i = 0; i < nr_sought; i++)
- free_one_ref(sought[i]);
+ free_one_ref(sought_to_free[i]);
+ free(sought_to_free);
free(sought);
free_refs(fetched_refs);
free_refs(remote_refs);
+ list_objects_filter_release(&args.filter_options);
+ oid_array_clear(&shallow);
+ string_list_clear(&pack_lockfiles, 0);
return ret;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index c900f57721..80a64d0d26 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -456,6 +456,7 @@ static void filter_prefetch_refspec(struct refspec *rs)
free(rs->items[i].src);
free(rs->items[i].dst);
+ free(rs->raw[i]);
for (j = i + 1; j < rs->nr; j++) {
rs->items[j - 1] = rs->items[j];
diff --git a/builtin/push.c b/builtin/push.c
index e6f48969b8..59d4485603 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -669,6 +669,7 @@ int cmd_push(int argc,
rc = do_push(flags, push_options, remote);
string_list_clear(&push_options_cmdline, 0);
string_list_clear(&push_options_config, 0);
+ clear_cas_option(&cas);
if (rc == -1)
usage_with_options(push_usage, options);
else
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 81fc96d423..8b1d46e79a 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -343,5 +343,7 @@ int cmd_send_pack(int argc,
free_refs(remote_refs);
free_refs(local_refs);
refspec_clear(&rs);
+ oid_array_clear(&shallow);
+ clear_cas_option(&cas);
return ret;
}
diff --git a/commit.c b/commit.c
index 3a54e4db0d..cc03a93036 100644
--- a/commit.c
+++ b/commit.c
@@ -595,7 +595,8 @@ int repo_parse_commit_internal(struct repository *r,
}
ret = parse_commit_buffer(r, item, buffer, size, 0);
- if (save_commit_buffer && !ret) {
+ if (save_commit_buffer && !ret &&
+ !get_cached_commit_buffer(r, item, NULL)) {
set_commit_buffer(r, item, buffer, size);
return 0;
}
diff --git a/connect.c b/connect.c
index 6829ab3974..58f53d8dcb 100644
--- a/connect.c
+++ b/connect.c
@@ -1485,6 +1485,7 @@ struct child_process *git_connect(int fd[2], const char *url,
free(hostandport);
free(path);
+ child_process_clear(conn);
free(conn);
strbuf_release(&cmd);
return NULL;
diff --git a/http-fetch.c b/http-fetch.c
index d460bb1837..02ab80533f 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -106,6 +106,7 @@ int cmd_main(int argc, const char **argv)
int nongit;
struct object_id packfile_hash;
struct strvec index_pack_args = STRVEC_INIT;
+ int ret;
setup_git_directory_gently(&nongit);
@@ -157,8 +158,8 @@ int cmd_main(int argc, const char **argv)
fetch_single_packfile(&packfile_hash, argv[arg],
index_pack_args.v);
-
- return 0;
+ ret = 0;
+ goto out;
}
if (index_pack_args.nr)
@@ -170,7 +171,12 @@ int cmd_main(int argc, const char **argv)
commit_id = (char **) &argv[arg++];
commits = 1;
}
- return fetch_using_walker(argv[arg], get_verbosely, get_recover,
- commits, commit_id, write_ref,
- commits_on_stdin);
+
+ ret = fetch_using_walker(argv[arg], get_verbosely, get_recover,
+ commits, commit_id, write_ref,
+ commits_on_stdin);
+
+out:
+ strvec_clear(&index_pack_args);
+ return ret;
}
diff --git a/http-push.c b/http-push.c
index 7315a694aa..aad89f2eab 100644
--- a/http-push.c
+++ b/http-push.c
@@ -275,7 +275,7 @@ static void start_fetch_loose(struct transfer_request *request)
if (!start_active_slot(slot)) {
fprintf(stderr, "Unable to start GET request\n");
repo->can_update_info_refs = 0;
- release_http_object_request(obj_req);
+ release_http_object_request(&obj_req);
release_request(request);
}
}
@@ -375,7 +375,7 @@ static void start_put(struct transfer_request *request)
/* Set it up */
git_deflate_init(&stream, zlib_compression_level);
size = git_deflate_bound(&stream, len + hdrlen);
- strbuf_init(&request->buffer.buf, size);
+ strbuf_grow(&request->buffer.buf, size);
request->buffer.posn = 0;
/* Compress it */
@@ -437,9 +437,11 @@ static void start_move(struct transfer_request *request)
if (start_active_slot(slot)) {
request->slot = slot;
request->state = RUN_MOVE;
+ request->headers = dav_headers;
} else {
request->state = ABORTED;
FREE_AND_NULL(request->url);
+ curl_slist_free_all(dav_headers);
}
}
@@ -512,6 +514,8 @@ static void release_request(struct transfer_request *request)
}
free(request->url);
+ free(request->dest);
+ strbuf_release(&request->buffer.buf);
free(request);
}
@@ -578,9 +582,10 @@ static void finish_request(struct transfer_request *request)
if (obj_req->rename == 0)
request->obj->flags |= (LOCAL | REMOTE);
+ release_http_object_request(&obj_req);
+
/* Try fetching packed if necessary */
if (request->obj->flags & LOCAL) {
- release_http_object_request(obj_req);
release_request(request);
} else
start_fetch_packed(request);
@@ -649,12 +654,10 @@ static void add_fetch_request(struct object *obj)
return;
obj->flags |= FETCHING;
- request = xmalloc(sizeof(*request));
+ CALLOC_ARRAY(request, 1);
request->obj = obj;
- request->url = NULL;
- request->lock = NULL;
- request->headers = NULL;
request->state = NEED_FETCH;
+ strbuf_init(&request->buffer.buf, 0);
request->next = request_queue_head;
request_queue_head = request;
@@ -685,12 +688,11 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
}
obj->flags |= PUSHING;
- request = xmalloc(sizeof(*request));
+ CALLOC_ARRAY(request, 1);
request->obj = obj;
- request->url = NULL;
request->lock = lock;
- request->headers = NULL;
request->state = NEED_PUSH;
+ strbuf_init(&request->buffer.buf, 0);
request->next = request_queue_head;
request_queue_head = request;
@@ -912,6 +914,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
result = XML_Parse(parser, in_buffer.buf,
in_buffer.len, 1);
free(ctx.name);
+ free(ctx.cdata);
if (result != XML_STATUS_OK) {
fprintf(stderr, "XML error: %s\n",
XML_ErrorString(
@@ -1169,6 +1172,7 @@ static void remote_ls(const char *path, int flags,
result = XML_Parse(parser, in_buffer.buf,
in_buffer.len, 1);
free(ctx.name);
+ free(ctx.cdata);
if (result != XML_STATUS_OK) {
fprintf(stderr, "XML error: %s\n",
@@ -1182,6 +1186,7 @@ static void remote_ls(const char *path, int flags,
}
free(ls.path);
+ free(ls.dentry_name);
free(url);
strbuf_release(&out_buffer.buf);
strbuf_release(&in_buffer);
@@ -1370,9 +1375,13 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
}
while (objects) {
+ struct object_list *next = objects->next;
+
if (!(objects->item->flags & UNINTERESTING))
count += add_send_request(objects->item, lock);
- objects = objects->next;
+
+ free(objects);
+ objects = next;
}
return count;
@@ -1398,6 +1407,7 @@ static int update_remote(const struct object_id *oid, struct remote_lock *lock)
if (start_active_slot(slot)) {
run_active_slot(slot);
strbuf_release(&out_buffer.buf);
+ curl_slist_free_all(dav_headers);
if (results.curl_result != CURLE_OK) {
fprintf(stderr,
"PUT error: curl result=%d, HTTP code=%ld\n",
@@ -1407,6 +1417,7 @@ static int update_remote(const struct object_id *oid, struct remote_lock *lock)
}
} else {
strbuf_release(&out_buffer.buf);
+ curl_slist_free_all(dav_headers);
fprintf(stderr, "Unable to start PUT request\n");
return 0;
}
@@ -1516,6 +1527,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
results.curl_result, results.http_code);
}
}
+ curl_slist_free_all(dav_headers);
}
strbuf_release(&buffer.buf);
}
@@ -1707,7 +1719,7 @@ int cmd_main(int argc, const char **argv)
int rc = 0;
int i;
int new_refs;
- struct ref *ref, *local_refs;
+ struct ref *ref, *local_refs = NULL;
CALLOC_ARRAY(repo, 1);
@@ -1972,6 +1984,7 @@ int cmd_main(int argc, const char **argv)
cleanup:
if (info_ref_lock)
unlock_remote(info_ref_lock);
+ free(repo->url);
free(repo);
http_cleanup();
@@ -1983,5 +1996,8 @@ int cmd_main(int argc, const char **argv)
request = next_request;
}
+ refspec_clear(&rs);
+ free_refs(local_refs);
+
return rc;
}
diff --git a/http-walker.c b/http-walker.c
index e417a7f51c..fb2d86d5e7 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -74,7 +74,7 @@ static void start_object_request(struct object_request *obj_req)
obj_req->state = ACTIVE;
if (!start_active_slot(slot)) {
obj_req->state = ABORTED;
- release_http_object_request(req);
+ release_http_object_request(&req);
return;
}
}
@@ -110,7 +110,7 @@ static void process_object_response(void *callback_data)
if (obj_req->repo->next) {
obj_req->repo =
obj_req->repo->next;
- release_http_object_request(obj_req->req);
+ release_http_object_request(&obj_req->req);
start_object_request(obj_req);
return;
}
@@ -495,7 +495,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
if (repo_has_object_file(the_repository, &obj_req->oid)) {
if (obj_req->req)
- abort_http_object_request(obj_req->req);
+ abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
return 0;
}
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
strbuf_release(&buf);
}
- release_http_object_request(req);
+ release_http_object_request(&obj_req->req);
release_object_request(obj_req);
return ret;
}
@@ -579,8 +579,18 @@ static void cleanup(struct walker *walker)
if (data) {
alt = data->alt;
while (alt) {
+ struct packed_git *pack;
+
alt_next = alt->next;
+ pack = alt->packs;
+ while (pack) {
+ struct packed_git *pack_next = pack->next;
+ close_pack(pack);
+ free(pack);
+ pack = pack_next;
+ }
+
free(alt->base);
free(alt);
diff --git a/http.c b/http.c
index 376af88c5d..d59e59f66b 100644
--- a/http.c
+++ b/http.c
@@ -800,6 +800,7 @@ static int redact_sensitive_header(struct strbuf *header, size_t offset)
strbuf_setlen(header, sensitive_header - header->buf);
strbuf_addbuf(header, &redacted_header);
+ strbuf_release(&redacted_header);
ret = 1;
}
return ret;
@@ -2474,6 +2475,7 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
cleanup:
free(url);
+ strbuf_release(&buf);
return ret;
}
@@ -2725,6 +2727,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
* file; also rewind to the beginning of the local file.
*/
if (prev_read == -1) {
+ git_inflate_end(&freq->stream);
memset(&freq->stream, 0, sizeof(freq->stream));
git_inflate_init(&freq->stream);
the_hash_algo->init_fn(&freq->c);
@@ -2798,7 +2801,6 @@ int finish_http_object_request(struct http_object_request *freq)
return -1;
}
- git_inflate_end(&freq->stream);
the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c);
if (freq->zret != Z_STREAM_END) {
unlink_or_warn(freq->tmpfile.buf);
@@ -2815,15 +2817,17 @@ int finish_http_object_request(struct http_object_request *freq)
return freq->rename;
}
-void abort_http_object_request(struct http_object_request *freq)
+void abort_http_object_request(struct http_object_request **freq_p)
{
+ struct http_object_request *freq = *freq_p;
unlink_or_warn(freq->tmpfile.buf);
- release_http_object_request(freq);
+ release_http_object_request(freq_p);
}
-void release_http_object_request(struct http_object_request *freq)
+void release_http_object_request(struct http_object_request **freq_p)
{
+ struct http_object_request *freq = *freq_p;
if (freq->localfile != -1) {
close(freq->localfile);
freq->localfile = -1;
@@ -2837,4 +2841,8 @@ void release_http_object_request(struct http_object_request *freq)
}
curl_slist_free_all(freq->headers);
strbuf_release(&freq->tmpfile);
+ git_inflate_end(&freq->stream);
+
+ free(freq);
+ *freq_p = NULL;
}
diff --git a/http.h b/http.h
index a516ca4a9a..46e334c2c2 100644
--- a/http.h
+++ b/http.h
@@ -240,8 +240,8 @@ struct http_object_request *new_http_object_request(
const char *base_url, const struct object_id *oid);
void process_http_object_request(struct http_object_request *freq);
int finish_http_object_request(struct http_object_request *freq);
-void abort_http_object_request(struct http_object_request *freq);
-void release_http_object_request(struct http_object_request *freq);
+void abort_http_object_request(struct http_object_request **freq);
+void release_http_object_request(struct http_object_request **freq);
/*
* Instead of using environment variables to determine if curl tracing happens,
diff --git a/refspec.c b/refspec.c
index ec90ab349a..c3cf003443 100644
--- a/refspec.c
+++ b/refspec.c
@@ -225,7 +225,7 @@ void refspec_clear(struct refspec *rs)
rs->nr = 0;
for (i = 0; i < rs->raw_nr; i++)
- free((char *)rs->raw[i]);
+ free(rs->raw[i]);
FREE_AND_NULL(rs->raw);
rs->raw_alloc = 0;
rs->raw_nr = 0;
diff --git a/refspec.h b/refspec.h
index 754be45cee..3760fdaf2b 100644
--- a/refspec.h
+++ b/refspec.h
@@ -43,7 +43,7 @@ struct refspec {
int alloc;
int nr;
- const char **raw;
+ char **raw;
int raw_alloc;
int raw_nr;
diff --git a/remote-curl.c b/remote-curl.c
index 4adcf25ed6..9a71e04301 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -347,7 +347,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
ref->next = refs;
refs = ref;
} else {
- free(ref);
+ free_one_ref(ref);
}
return refs;
diff --git a/remote.c b/remote.c
index 390a03c264..e291e8ff5c 100644
--- a/remote.c
+++ b/remote.c
@@ -2544,7 +2544,7 @@ struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map)
/*
* Compare-and-swap
*/
-static void clear_cas_option(struct push_cas_option *cas)
+void clear_cas_option(struct push_cas_option *cas)
{
int i;
diff --git a/remote.h b/remote.h
index a58713f20a..ad4513f639 100644
--- a/remote.h
+++ b/remote.h
@@ -409,6 +409,7 @@ struct push_cas_option {
};
int parseopt_push_cas_option(const struct option *, const char *arg, int unset);
+void clear_cas_option(struct push_cas_option *);
int is_empty_cas(const struct push_cas_option *);
void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *);
diff --git a/shallow.c b/shallow.c
index dcebc263d7..4bb1518dbc 100644
--- a/shallow.c
+++ b/shallow.c
@@ -51,12 +51,11 @@ int unregister_shallow(const struct object_id *oid)
int pos = commit_graft_pos(the_repository, oid);
if (pos < 0)
return -1;
- if (pos + 1 < the_repository->parsed_objects->grafts_nr) {
- free(the_repository->parsed_objects->grafts[pos]);
+ free(the_repository->parsed_objects->grafts[pos]);
+ if (pos + 1 < the_repository->parsed_objects->grafts_nr)
MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
the_repository->parsed_objects->grafts + pos + 1,
the_repository->parsed_objects->grafts_nr - pos - 1);
- }
the_repository->parsed_objects->grafts_nr--;
return 0;
}
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 585ea0ee16..605f17240c 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -8,6 +8,7 @@ test_description='Testing multi_ack pack fetching'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# Test fetch-pack/upload-pack pair.
diff --git a/t/t5539-fetch-http-shallow.sh b/t/t5539-fetch-http-shallow.sh
index 3ea75d34ca..82fe09d0a9 100755
--- a/t/t5539-fetch-http-shallow.sh
+++ b/t/t5539-fetch-http-shallow.sh
@@ -5,6 +5,7 @@ test_description='fetch/clone from a shallow clone over http'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
diff --git a/t/t5540-http-push-webdav.sh b/t/t5540-http-push-webdav.sh
index 37db3dec0c..27389b0908 100755
--- a/t/t5540-http-push-webdav.sh
+++ b/t/t5540-http-push-webdav.sh
@@ -10,6 +10,7 @@ This test runs various sanity checks on http-push.'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh
index 71428f3d5c..3ad514bbd4 100755
--- a/t/t5541-http-push-smart.sh
+++ b/t/t5541-http-push-smart.sh
@@ -7,6 +7,7 @@ test_description='test smart pushing over http via http-backend'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
ROOT_PATH="$PWD"
diff --git a/t/t5542-push-http-shallow.sh b/t/t5542-push-http-shallow.sh
index c2cc83182f..07624a1d7f 100755
--- a/t/t5542-push-http-shallow.sh
+++ b/t/t5542-push-http-shallow.sh
@@ -5,6 +5,7 @@ test_description='push from/to a shallow clone over http'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index ea8e48f627..58189c9f7d 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -4,6 +4,7 @@ test_description='test dumb fetching over http via static file'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
if test_have_prereq !REFFILES
diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
index ceb3336a5c..2ce88535a6 100755
--- a/t/t5551-http-fetch-smart.sh
+++ b/t/t5551-http-fetch-smart.sh
@@ -5,6 +5,7 @@ test_description="test smart fetching over http via http-backend ($HTTP_PROTO)"
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
test "$HTTP_PROTO" = "HTTP/2" && enable_http2
diff --git a/t/t5582-fetch-negative-refspec.sh b/t/t5582-fetch-negative-refspec.sh
index 7a80e47c2b..7fa54a4029 100755
--- a/t/t5582-fetch-negative-refspec.sh
+++ b/t/t5582-fetch-negative-refspec.sh
@@ -8,6 +8,7 @@ test_description='"git fetch" with negative refspecs.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
diff --git a/t/t5619-clone-local-ambiguous-transport.sh b/t/t5619-clone-local-ambiguous-transport.sh
index cce62bf78d..1d4efe414d 100755
--- a/t/t5619-clone-local-ambiguous-transport.sh
+++ b/t/t5619-clone-local-ambiguous-transport.sh
@@ -2,6 +2,7 @@
test_description='test local clone with ambiguous transport'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY/lib-httpd.sh"
diff --git a/t/t5700-protocol-v1.sh b/t/t5700-protocol-v1.sh
index a73b4d4ff6..985e04d06e 100755
--- a/t/t5700-protocol-v1.sh
+++ b/t/t5700-protocol-v1.sh
@@ -11,6 +11,7 @@ export GIT_TEST_PROTOCOL_VERSION
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# Test protocol v1 with 'git://' transport
diff --git a/transport-helper.c b/transport-helper.c
index c688967b8c..013ec79dc9 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -717,8 +717,14 @@ static int fetch_refs(struct transport *transport,
return -1;
}
- if (!data->get_refs_list_called)
- get_refs_list_using_list(transport, 0);
+ if (!data->get_refs_list_called) {
+ /*
+ * We do not care about the list of refs returned, but only
+ * that the "list" command was sent.
+ */
+ struct ref *dummy = get_refs_list_using_list(transport, 0);
+ free_refs(dummy);
+ }
count = 0;
for (i = 0; i < nr_heads; i++)
@@ -1023,6 +1029,7 @@ static int push_refs_with_push(struct transport *transport,
if (atomic) {
reject_atomic_push(remote_refs, mirror);
string_list_clear(&cas_options, 0);
+ strbuf_release(&buf);
return 0;
} else
continue;
diff --git a/transport.c b/transport.c
index 3c4714581f..1098bbd60e 100644
--- a/transport.c
+++ b/transport.c
@@ -414,7 +414,7 @@ static int fetch_refs_via_pack(struct transport *transport,
struct git_transport_data *data = transport->data;
struct ref *refs = NULL;
struct fetch_pack_args args;
- struct ref *refs_tmp = NULL;
+ struct ref *refs_tmp = NULL, **to_fetch_dup = NULL;
memset(&args, 0, sizeof(args));
args.uploadpack = data->options.uploadpack;
@@ -477,6 +477,14 @@ static int fetch_refs_via_pack(struct transport *transport,
goto cleanup;
}
+ /*
+ * Create a shallow copy of `sought` so that we can free all of its entries.
+ * This is because `fetch_pack()` will modify the array to evict some
+ * entries, but won't free those.
+ */
+ DUP_ARRAY(to_fetch_dup, to_fetch, nr_heads);
+ to_fetch = to_fetch_dup;
+
refs = fetch_pack(&args, data->fd,
refs_tmp ? refs_tmp : transport->remote_refs,
to_fetch, nr_heads, &data->shallow,
@@ -500,6 +508,7 @@ cleanup:
ret = -1;
data->conn = NULL;
+ free(to_fetch_dup);
free_refs(refs_tmp);
free_refs(refs);
list_objects_filter_release(&args.filter_options);