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>next
parent
ab776a62a7
commit
0201d2783e
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue