Skip to content

Commit 323822c

Browse files
avargitster
authored andcommitted
remote.c: don't dereference NULL in freeing loop
Fix a bug in fd3cb05 (remote: move static variables into per-repository struct, 2021-11-17) where we'd free(remote->pushurl[i]) after having NULL'd out remote->pushurl. itself. We free "remote->pushurl" in the next "for"-loop, so doing this appears to have been a copy/paste error. Before this change GCC 12's -fanalyzer would correctly note that we'd dereference NULL in this case, this change fixes that: remote.c: In function ‘remote_clear’: remote.c:153:17: error: dereference of NULL ‘*remote.pushurl’ [CWE-476] [-Werror=analyzer-null-dereference] 153 | free((char *)remote->pushurl[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [...] Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 338959d commit 323822c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void remote_clear(struct remote *remote)
146146

147147
for (i = 0; i < remote->url_nr; i++)
148148
free((char *)remote->url[i]);
149-
FREE_AND_NULL(remote->pushurl);
149+
FREE_AND_NULL(remote->url);
150150

151151
for (i = 0; i < remote->pushurl_nr; i++)
152152
free((char *)remote->pushurl[i]);

0 commit comments

Comments
 (0)