All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] remote: plug memory leaks
@ 2026-07-25  0:43 Junio C Hamano
  2026-07-25  1:57 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2026-07-25  0:43 UTC (permalink / raw)
  To: git; +Cc: Éric NICOLAS

The in-core data structure used to keep track of
'url.<real>.{insteadOf,pushInsteadOf} = <alias>' settings is not
properly cleaned up when the process is done with it.

Fix the rewrites_release() function to free not just the 'struct
rewrites' instance itself, but also allocated structures that are
pointed at by the 'struct rewrites' instance.  One of the embedded
structures holds a 'const char *' to point at a borrowed constant
string from a configuration callback.  Since the code does not
modify this string, stop copying the value (alias URL) before
registering it in 'struct rewrite', as nobody is freeing this
member, to avoid leaking the extra copy.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * These are not recently introduced leaks as far as I can tell, but
   the new tests in en/submodule-insteadof-remote-match expose them.

 remote.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/remote.c b/remote.c
index 368a43c1b2..e3d4b25040 100644
--- a/remote.c
+++ b/remote.c
@@ -309,8 +309,11 @@ static struct rewrite *make_rewrite(struct rewrites *r,
 
 static void rewrites_release(struct rewrites *r)
 {
-	for (int i = 0; i < r->rewrite_nr; i++)
+	for (int i = 0; i < r->rewrite_nr; i++) {
 		free((char *)r->rewrite[i]->base);
+		free(r->rewrite[i]->instead_of);
+		free(r->rewrite[i]);
+	}
 	free(r->rewrite);
 	memset(r, 0, sizeof(*r));
 }
@@ -469,13 +472,13 @@ static int handle_config(const char *key, const char *value,
 				return config_error_nonbool(key);
 			rewrite = make_rewrite(&remote_state->rewrites, name,
 					       namelen);
-			add_instead_of(rewrite, xstrdup(value));
+			add_instead_of(rewrite, value);
 		} else if (!strcmp(subkey, "pushinsteadof")) {
 			if (!value)
 				return config_error_nonbool(key);
 			rewrite = make_rewrite(&remote_state->rewrites_push,
 					       name, namelen);
-			add_instead_of(rewrite, xstrdup(value));
+			add_instead_of(rewrite, value);
 		}
 	}
 
-- 
2.55.0-576-g1c3ad6b142


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] remote: plug memory leaks
  2026-07-25  0:43 [PATCH] remote: plug memory leaks Junio C Hamano
@ 2026-07-25  1:57 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2026-07-25  1:57 UTC (permalink / raw)
  To: git, Ted Nyman; +Cc: Éric NICOLAS

Junio C Hamano <gitster@pobox.com> writes:

> The in-core data structure used to keep track of
> 'url.<real>.{insteadOf,pushInsteadOf} = <alias>' settings is not
> properly cleaned up when the process is done with it.
>
> Fix the rewrites_release() function to free not just the 'struct
> rewrites' instance itself, but also allocated structures that are
> pointed at by the 'struct rewrites' instance.  One of the embedded
> structures holds a 'const char *' to point at a borrowed constant
> string from a configuration callback.  Since the code does not
> modify this string, stop copying the value (alias URL) before
> registering it in 'struct rewrite', as nobody is freeing this
> member, to avoid leaking the extra copy.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
>  * These are not recently introduced leaks as far as I can tell, but
>    the new tests in en/submodule-insteadof-remote-match expose them.

It is unfortunately rare to see all CI jobs pass, but today is one
of those days ;-)

With this, and everything in 'seen' reported in the last edition of
the "What's cooking" report, excluding the
'tn/packfile-uri-concurrency' topic, CI passes all jobs.

  https://github.com/git/git/actions/runs/30137079882/

'tn/packfile-uri-concurrency' was tentatively excluded from the
above as I made a random guess at who the culprit for the t5550
failure in

  https://github.com/git/git/actions/runs/30130205851/job/89602846186

for the SHA-256 CI job was.  I have merged the topic back into
'seen', and the resulting CI run for 'seen' is here:

  https://github.com/git/git/actions/runs/30138777784/

It has not finished running, so we'll see how it goes.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-25  1:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25  0:43 [PATCH] remote: plug memory leaks Junio C Hamano
2026-07-25  1:57 ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.