]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule: fix leaking fetch tasks
authorPatrick Steinhardt <ps@pks.im>
Thu, 8 Aug 2024 07:35:51 +0000 (09:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Aug 2024 16:22:21 +0000 (09:22 -0700)
When done with a fetch task used for parallel fetches of submodules, we
need to both call `fetch_task_release()` to release the task's contents
and `free()` to release the task itself. Most sites do this already, but
some only call `fetch_task_release()` and thus leak memory.

While we could trivially fix this by adding the two missing calls to
free(3P), the result would be that we always call both functions. Let's
thus refactor the code such that `fetch_task_release()` also frees the
structure itself. Rename it to `fetch_task_free()` accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c

index ab99a30253083bc9f4d53120ed27b53d1caca2a1..f027a6455ebeb8f79b7b7bd5ddcb746f427d9576 100644 (file)
@@ -1496,7 +1496,7 @@ static const struct submodule *get_non_gitmodules_submodule(const char *path)
        return (const struct submodule *) ret;
 }
 
-static void fetch_task_release(struct fetch_task *p)
+static void fetch_task_free(struct fetch_task *p)
 {
        if (p->free_sub)
                free((void*)p->sub);
@@ -1508,6 +1508,7 @@ static void fetch_task_release(struct fetch_task *p)
        FREE_AND_NULL(p->repo);
 
        strvec_clear(&p->git_args);
+       free(p);
 }
 
 static struct repository *get_submodule_repo_for(struct repository *r,
@@ -1576,8 +1577,7 @@ static struct fetch_task *fetch_task_create(struct submodule_parallel_fetch *spf
        return task;
 
  cleanup:
-       fetch_task_release(task);
-       free(task);
+       fetch_task_free(task);
        return NULL;
 }
 
@@ -1607,8 +1607,7 @@ get_fetch_task_from_index(struct submodule_parallel_fetch *spf,
                } else {
                        struct strbuf empty_submodule_path = STRBUF_INIT;
 
-                       fetch_task_release(task);
-                       free(task);
+                       fetch_task_free(task);
 
                        /*
                         * An empty directory is normal,
@@ -1654,8 +1653,7 @@ get_fetch_task_from_changed(struct submodule_parallel_fetch *spf,
                                    cs_data->path,
                                    repo_find_unique_abbrev(the_repository, cs_data->super_oid, DEFAULT_ABBREV));
 
-                       fetch_task_release(task);
-                       free(task);
+                       fetch_task_free(task);
                        continue;
                }
 
@@ -1763,7 +1761,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
 
        spf->result = 1;
 
-       fetch_task_release(task);
+       fetch_task_free(task);
        return 0;
 }
 
@@ -1828,8 +1826,7 @@ static int fetch_finish(int retvalue, struct strbuf *err UNUSED,
        }
 
 out:
-       fetch_task_release(task);
-
+       fetch_task_free(task);
        return 0;
 }