clone: plug a miniscule leak

The remote_name variable is first assigned a copy of the value of the "clone.defaultremotename" configuration variable and then by the value of the "--origin" command line option. The former is prepared to see multiple instances of the configuration variable by freeing the current value of the variable before a copy of the newly discovered value gets assigned to it. The latter however blindly assigned a copy of the new value to the variable, thereby leaking the value read from the configuration variable. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 30, 2022 at 22:17 UTC 6dfadc8981a3f2fd3fb552eb956fe12a542f8ee8
1 file changed +3 -1
builtin/clone.c
+3 -1
@@ -1106,8 +1106,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1106 * apply the remote name provided by --origin only after this second
1107 * call to git_config, to ensure it overrides all config-based values.
1108 */
1109 - if (option_origin != NULL)
1109 + if (option_origin != NULL) {
1110 + free(remote_name);
1111 remote_name = xstrdup(option_origin);
1112 + }
1113
1114 if (remote_name == NULL)
1115 remote_name = xstrdup("origin");