repository: introduce repo_config_values_clear()
As part of the ongoing libification effort, dynamically allocated global configuration variables are being moved into 'struct repo_config_values'. To prevent memory leaks, we need a destructor to free these heap-allocated variables when a repository instance is torn down. Introduce 'repo_config_values_clear()' in environment.c and invoke it from 'repo_clear()' in repository.c. As a starting point, update this new function to handle the cleanup of 'attributes_file'. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tian Yuchen committed
Jul 14, 2026 at 11:25 UTC
0201d2783e6317c7b76e9c511cbfcfa73fdc17b1
3 files changed
+15
environment.c
+5
@@ -726,3 +726,8 @@ void repo_config_values_init(struct repo_config_values *cfg)
726
cfg->sparse_expect_files_outside_of_patterns = 0;
727
cfg->warn_on_object_refname_ambiguity = 1;
728
}
729
+
730
+void repo_config_values_clear(struct repo_config_values *cfg)
731
+{
732
+ FREE_AND_NULL(cfg->attributes_file);
733
+}
environment.h
+9
@@ -135,6 +135,15 @@ int git_default_core_config(const char *var, const char *value,
135
136
void repo_config_values_init(struct repo_config_values *cfg);
137
138
+/*
139
+ * Frees memory allocated for dynamically loaded configuration values
140
+ * inside `repo_config_values`.
141
+ *
142
+ * As dynamically allocated variables are migrated into this struct,
143
+ * their FREE_AND_NULL() calls should be appended here.
144
+ */
145
+void repo_config_values_clear(struct repo_config_values *cfg);
146
+
147
/*
148
* TODO: All the below state either explicitly or implicitly relies on
149
* `the_repository`. We should eventually get rid of these and make the
repository.c
+1
@@ -388,6 +388,7 @@ void repo_clear(struct repository *repo)
388
FREE_AND_NULL(repo->parsed_objects);
389
390
repo_settings_clear(repo);
391
+ repo_config_values_clear(&repo->config_values_private_);
392
393
if (repo->config) {
394
git_configset_clear(repo->config);