Merge branch 'ab/remote-free-fix'

Use-after-free (with another forget-to-free) fix.

* ab/remote-free-fix:
  remote.c: don't dereference NULL in freeing loop
  remote.c: remove braces from one-statement "for"-loops
This commit is contained in:
Junio C Hamano 2022-06-13 15:53:43 -07:00
commit fe66167535

View File

@ -146,14 +146,12 @@ static void remote_clear(struct remote *remote)
free((char *)remote->name);
free((char *)remote->foreign_vcs);
for (i = 0; i < remote->url_nr; i++) {
for (i = 0; i < remote->url_nr; i++)
free((char *)remote->url[i]);
}
FREE_AND_NULL(remote->pushurl);
FREE_AND_NULL(remote->url);
for (i = 0; i < remote->pushurl_nr; i++) {
for (i = 0; i < remote->pushurl_nr; i++)
free((char *)remote->pushurl[i]);
}
FREE_AND_NULL(remote->pushurl);
free((char *)remote->receivepack);
free((char *)remote->uploadpack);
@ -2771,9 +2769,8 @@ void remote_state_clear(struct remote_state *remote_state)
{
int i;
for (i = 0; i < remote_state->remotes_nr; i++) {
for (i = 0; i < remote_state->remotes_nr; i++)
remote_clear(remote_state->remotes[i]);
}
FREE_AND_NULL(remote_state->remotes);
remote_state->remotes_alloc = 0;
remote_state->remotes_nr = 0;