Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2023-02-07 02:07:45 +0300
committerJunio C Hamano <gitster@pobox.com>2023-02-07 02:34:38 +0300
commit2139bd0200b2ee51674d8778cd26a9f38220a5b7 (patch)
tree61548395890da8417c6779ab32c80e2f1c0b14de /http-backend.c
parenteef75d247a5f1ce07cb21fa05196cdf7bc443e13 (diff)
http-backend.c: fix cmd_main() memory leak, refactor reg{exec,free}()
Fix a memory leak that's been with us ever since 2f4038ab337 (Git-aware CGI to provide dumb HTTP transport, 2009-10-30). In this case we're not calling regerror() after a failed regexec(), and don't otherwise use "re" afterwards. We can therefore simplify this code by calling regfree() right after the regexec(). An alternative fix would be to add a regfree() to both the "return" and "break" path in this for-loop. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'http-backend.c')
-rw-r--r--http-backend.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/http-backend.c b/http-backend.c
index 67819d931c..8ab58e55f8 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -759,10 +759,14 @@ int cmd_main(int argc, const char **argv)
struct service_cmd *c = &services[i];
regex_t re;
regmatch_t out[1];
+ int ret;
if (regcomp(&re, c->pattern, REG_EXTENDED))
die("Bogus regex in service table: %s", c->pattern);
- if (!regexec(&re, dir, 1, out, 0)) {
+ ret = regexec(&re, dir, 1, out, 0);
+ regfree(&re);
+
+ if (!ret) {
size_t n;
if (strcmp(method, c->method))
@@ -774,7 +778,6 @@ int cmd_main(int argc, const char **argv)
dir[out[0].rm_so] = 0;
break;
}
- regfree(&re);
}
if (!cmd)