git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 04/23] submodule: fix leaking update strategy

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 26, 2024, 11:46 UTC
Message-ID
<7cdd2691b77d328447855f898540f7efb2a415c3.1727351062.git.ps@pks.im>
In-Reply-To
<cover.1727351062.git.ps@pks.im>

We're not freeing the submodule update strategy command. Provide a helper function that does this for us and call it in `update_data_release()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/submodule--helper.c | 1 +
 submodule-config.c          | 2 +-
 submodule.c                 | 5 +++++
 submodule.h                 | 6 ++++--
 t/t7406-submodule-update.sh | 1 +
 5 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index bf8f9a4012..ed05dc5134 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2021,6 +2021,7 @@ struct update_data {
 static void update_data_release(struct update_data *ud)
 {
 	free(ud->displaypath);
+	submodule_update_strategy_release(&ud->update_strategy);
 	module_list_release(&ud->list);
 }
 
diff --git a/submodule-config.c b/submodule-config.c
index c8f2bb2bdd..471637a725 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -95,7 +95,7 @@ static void free_one_config(struct submodule_entry *entry)
 	free((void *) entry->config->branch);
 	free((void *) entry->config->url);
 	free((void *) entry->config->ignore);
-	free((void *) entry->config->update_strategy.command);
+	submodule_update_strategy_release(&entry->config->update_strategy);
 	free(entry->config);
 }
 
diff --git a/submodule.c b/submodule.c
index 97d0d47b56..0e67984d77 100644
--- a/submodule.c
+++ b/submodule.c
@@ -424,6 +424,11 @@ int parse_submodule_update_strategy(const char *value,
 	return 0;
 }
 
+void submodule_update_strategy_release(struct submodule_update_strategy *strategy)
+{
+	free((char *) strategy->command);
+}
+
 const char *submodule_update_type_to_string(enum submodule_update_type type)
 {
 	switch (type) {
diff --git a/submodule.h b/submodule.h
index b50d29eba4..4deb1b5f84 100644
--- a/submodule.h
+++ b/submodule.h
@@ -41,6 +41,10 @@ struct submodule_update_strategy {
 	.type = SM_UPDATE_UNSPECIFIED, \
 }
 
+int parse_submodule_update_strategy(const char *value,
+				    struct submodule_update_strategy *dst);
+void submodule_update_strategy_release(struct submodule_update_strategy *strategy);
+
 int is_gitmodules_unmerged(struct index_state *istate);
 int is_writing_gitmodules_ok(void);
 int is_staging_gitmodules_ok(struct index_state *istate);
@@ -70,8 +74,6 @@ void die_in_unpopulated_submodule(struct index_state *istate,
 void die_path_inside_submodule(struct index_state *istate,
 			       const struct pathspec *ps);
 enum submodule_update_type parse_submodule_update_type(const char *value);
-int parse_submodule_update_strategy(const char *value,
-				    struct submodule_update_strategy *dst);
 const char *submodule_update_type_to_string(enum submodule_update_type type);
 void handle_ignore_submodules_arg(struct diff_options *, const char *);
 void show_submodule_diff_summary(struct diff_options *o, const char *path,
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 297c6c3b5c..0f0c86f9cb 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -12,6 +12,7 @@ submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 
-- 
2.46.2.852.g229c0bf0e5.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 43 of 62 in “Memory leak fixes (pt.7)”
  1. 00/23 Memory leak fixes (pt.7)Patrick Steinhardt, Sep 16, 2024
  2. 01/23 builtin/help: fix dangling reference to `html_path`Patrick Steinhardt, Sep 16, 2024
  3. Justin ToblerSep 16, 2024
  4. 02/23 builtin/help: fix leaking `html_path` when reading config multiple timesPatrick Steinhardt, Sep 16, 2024
  5. 03/23 git: fix leaking argv when handling builtinsPatrick Steinhardt, Sep 16, 2024
  6. 04/23 submodule: fix leaking update strategyPatrick Steinhardt, Sep 16, 2024
  7. 05/23 builtin/submodule--helper: clear child process when not running itPatrick Steinhardt, Sep 16, 2024
  8. 06/23 builtin/submodule--helper: fix leaking error bufferPatrick Steinhardt, Sep 16, 2024
  9. 07/23 t/helper: fix leaking subrepo in nested submodule config helperPatrick Steinhardt, Sep 16, 2024
  10. 08/23 builtin/submodule--helper: fix leaking remote ref on errorsPatrick Steinhardt, Sep 16, 2024
  11. Justin ToblerSep 16, 2024
  12. Patrick SteinhardtSep 17, 2024
  13. Junio C HamanoSep 25, 2024
  14. Patrick SteinhardtSep 26, 2024
  15. 09/23 dir: fix off by one errors for ignored and untracked entriesPatrick Steinhardt, Sep 16, 2024
  16. Junio C HamanoSep 20, 2024
  17. 10/23 builtin/pull: fix leaking "ff" optionPatrick Steinhardt, Sep 16, 2024
  18. Junio C HamanoSep 20, 2024
  19. Patrick SteinhardtSep 24, 2024
  20. 11/23 diff: fix leaking orderfile optionPatrick Steinhardt, Sep 16, 2024
  21. 12/23 parse-options: free previous value of `OPTION_FILENAME`Patrick Steinhardt, Sep 16, 2024
  22. Junio C HamanoSep 20, 2024
  23. 13/23 diffcore-order: fix leaking buffer when parsing orderfilesPatrick Steinhardt, Sep 16, 2024
  24. 14/23 builtin/repack: fix leaking configurationPatrick Steinhardt, Sep 16, 2024
  25. Junio C HamanoSep 20, 2024
  26. 15/23 builtin/difftool: plug several trivial memory leaksPatrick Steinhardt, Sep 16, 2024
  27. 16/23 trace2: destroy context stored in thread-local storagePatrick Steinhardt, Sep 16, 2024
  28. 17/23 submodule: fix leaking submodule ODB pathsPatrick Steinhardt, Sep 16, 2024
  29. 18/23 grep: fix leaking grep patternPatrick Steinhardt, Sep 16, 2024
  30. 19/23 promisor-remote: fix leaking partial clone filterPatrick Steinhardt, Sep 16, 2024
  31. 20/23 builtin/maintenance: fix leaking config stringPatrick Steinhardt, Sep 16, 2024
  32. Junio C HamanoSep 20, 2024
  33. 21/23 builtin/maintenance: fix leak in `get_schedule_cmd()`Patrick Steinhardt, Sep 16, 2024
  34. 22/23 revision: fix leaking parents when simplifying commitsPatrick Steinhardt, Sep 16, 2024
  35. Junio C HamanoSep 19, 2024
  36. 23/23 diffcore-break: fix leaking filespecs when merging broken pairsPatrick Steinhardt, Sep 16, 2024
  37. Junio C HamanoSep 19, 2024
  38. Patrick SteinhardtSep 24, 2024
  39. 00/23 Memory leak fixes (pt.7)Patrick Steinhardt, Sep 26, 2024
  40. 01/23 builtin/help: fix dangling reference to `html_path`Patrick Steinhardt, Sep 26, 2024
  41. 02/23 builtin/help: fix leaking `html_path` when reading config multiple timesPatrick Steinhardt, Sep 26, 2024
  42. 03/23 git: fix leaking argv when handling builtinsPatrick Steinhardt, Sep 26, 2024
  43. 04/23 submodule: fix leaking update strategyPatrick Steinhardt, Sep 26, 2024
  44. 05/23 builtin/submodule--helper: clear child process when not running itPatrick Steinhardt, Sep 26, 2024
  45. 06/23 builtin/submodule--helper: fix leaking error bufferPatrick Steinhardt, Sep 26, 2024
  46. 07/23 t/helper: fix leaking subrepo in nested submodule config helperPatrick Steinhardt, Sep 26, 2024
  47. 08/23 builtin/submodule--helper: fix leaking remote ref on errorsPatrick Steinhardt, Sep 26, 2024
  48. 09/23 dir: fix off by one errors for ignored and untracked entriesPatrick Steinhardt, Sep 26, 2024
  49. 10/23 builtin/pull: fix leaking "ff" optionPatrick Steinhardt, Sep 26, 2024
  50. 11/23 diff: fix leaking orderfile optionPatrick Steinhardt, Sep 26, 2024
  51. 12/23 parse-options: free previous value of `OPTION_FILENAME`Patrick Steinhardt, Sep 26, 2024
  52. 13/23 diffcore-order: fix leaking buffer when parsing orderfilesPatrick Steinhardt, Sep 26, 2024
  53. 14/23 builtin/repack: fix leaking configurationPatrick Steinhardt, Sep 26, 2024
  54. 15/23 builtin/difftool: plug several trivial memory leaksPatrick Steinhardt, Sep 26, 2024
  55. 16/23 trace2: destroy context stored in thread-local storagePatrick Steinhardt, Sep 26, 2024
  56. 17/23 submodule: fix leaking submodule ODB pathsPatrick Steinhardt, Sep 26, 2024
  57. 18/23 grep: fix leaking grep patternPatrick Steinhardt, Sep 26, 2024
  58. 19/23 promisor-remote: fix leaking partial clone filterPatrick Steinhardt, Sep 26, 2024
  59. 20/23 builtin/maintenance: fix leaking config stringPatrick Steinhardt, Sep 26, 2024
  60. 21/23 builtin/maintenance: fix leak in `get_schedule_cmd()`Patrick Steinhardt, Sep 26, 2024
  61. 22/23 revision: fix leaking parents when simplifying commitsPatrick Steinhardt, Sep 26, 2024
  62. 23/23 diffcore-break: fix leaking filespecs when merging broken pairsPatrick Steinhardt, Sep 26, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.