Skip to content

Commit a41e8e7

Browse files
avargitster
authored andcommitted
urlmatch.c: add and use a *_release() function
Plug a memory leak in credential_apply_config() by adding and using a new urlmatch_config_release() function. This just does a string_list_clear() on the "vars" member. This finished up work on normalizing the init/free pattern in this API, started in 73ee449 (urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT, 2021-10-01). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a18d66c commit a41e8e7

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

builtin/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ static int get_urlmatch(const char *var, const char *url)
612612

613613
strbuf_release(&matched->value);
614614
}
615-
string_list_clear(&config.vars, 1);
615+
urlmatch_config_release(&config);
616616
string_list_clear(&values, 1);
617617
free(config.url.url);
618618

credential.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static void credential_apply_config(struct credential *c)
130130
git_config(urlmatch_config_entry, &config);
131131
string_list_clear(&config.vars, 1);
132132
free(normalized_url);
133+
urlmatch_config_release(&config);
133134
strbuf_release(&url);
134135

135136
c->configured = 1;

urlmatch.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,8 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
611611
strbuf_release(&synthkey);
612612
return retval;
613613
}
614+
615+
void urlmatch_config_release(struct urlmatch_config *config)
616+
{
617+
string_list_clear(&config->vars, 1);
618+
}

urlmatch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ struct urlmatch_config {
7171
}
7272

7373
int urlmatch_config_entry(const char *var, const char *value, void *cb);
74+
void urlmatch_config_release(struct urlmatch_config *config);
7475

7576
#endif /* URL_MATCH_H */

0 commit comments

Comments
 (0)