]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository: introduce repo_config_values_clear()
authorTian Yuchen <cat@malon.dev>
Tue, 14 Jul 2026 03:25:16 +0000 (11:25 +0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Jul 2026 14:30:23 +0000 (07:30 -0700)
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>
environment.c
environment.h
repository.c

index ba2c60103ff51c5e50a6c0e08635c9a3453eead6..ae05f16d041858e99431fc6ef1187558fce059af 100644 (file)
@@ -726,3 +726,8 @@ void repo_config_values_init(struct repo_config_values *cfg)
        cfg->sparse_expect_files_outside_of_patterns = 0;
        cfg->warn_on_object_refname_ambiguity = 1;
 }
+
+void repo_config_values_clear(struct repo_config_values *cfg)
+{
+       FREE_AND_NULL(cfg->attributes_file);
+}
index 6f182869558395caeaf6f0595c331564ccf0d8c7..9169d7f62d994106b85a9416e00211d4d16779aa 100644 (file)
@@ -135,6 +135,15 @@ int git_default_core_config(const char *var, const char *value,
 
 void repo_config_values_init(struct repo_config_values *cfg);
 
+/*
+ * Frees memory allocated for dynamically loaded configuration values
+ * inside `repo_config_values`.
+ *
+ * As dynamically allocated variables are migrated into this struct,
+ * their FREE_AND_NULL() calls should be appended here.
+ */
+void repo_config_values_clear(struct repo_config_values *cfg);
+
 /*
  * TODO: All the below state either explicitly or implicitly relies on
  * `the_repository`. We should eventually get rid of these and make the
index 187dd471c4e607910f093aec6cdb641f382d1229..669e2d12004d77227ebc72758ac29ab38a43752b 100644 (file)
@@ -388,6 +388,7 @@ void repo_clear(struct repository *repo)
        FREE_AND_NULL(repo->parsed_objects);
 
        repo_settings_clear(repo);
+       repo_config_values_clear(&repo->config_values_private_);
 
        if (repo->config) {
                git_configset_clear(repo->config);