]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote.c: don't dereference NULL in freeing loop
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 7 Jun 2022 15:50:04 +0000 (17:50 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Jun 2022 17:23:47 +0000 (10:23 -0700)
Fix a bug in fd3cb0501e1 (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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c

index eb07b667db68022481278ecc226dea9808ca2745..bb55038e4c734afda89deb8b8f37f6126c6a92d2 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -146,7 +146,7 @@ static void remote_clear(struct remote *remote)
 
        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++)
                free((char *)remote->pushurl[i]);