mingw: avoid memory leak when splitting PATH
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 4 May 2017 13:55:24 +0000 (15:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 03:18:19 +0000 (12:18 +0900)
In the (admittedly, concocted) case that PATH consists only of path
delimiters, we would leak the duplicated string.

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c
index 3fbfda5978b7bb715ab132283a69fa49384896e9..fe0e3ccd24887a830b99dabb9c66db668ba4f566 100644 (file)
@@ -961,8 +961,10 @@ static char **get_path_split(void)
                        ++n;
                }
        }
-       if (!n)
+       if (!n) {
+               free(envpath);
                return NULL;
+       }
 
        ALLOC_ARRAY(path, n + 1);
        p = envpath;