Skip to content

Commit 759f340

Browse files
avargitster
authored andcommitted
repository.c: free the "path cache" in repo_clear()
The "struct path_cache" added in 102de88 (path.c: migrate global git_path_* to take a repository argument, 2018-05-17) is only used directly by code in repository.[ch] (but populated in path.[ch]). Let's move this code to repository.[ch], and stop leaking this memory when we run repo_clear(). To avoid the cast change it from a "const char *" to a "char *". This also removes the "PATH_CACHE_INIT" macro, which has never been used for anything. For the "struct repository" we already make a hard assumption that it (and "the_repository") can be identically initialized by making it a "static" variable, so making use of a "PATH_CACHE_INIT" somewhere would have been confusing. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d102c2 commit 759f340

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

path.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,6 @@ void report_linked_checkout_garbage(void);
169169
return r->cached_paths.var; \
170170
}
171171

172-
struct path_cache {
173-
const char *squash_msg;
174-
const char *merge_msg;
175-
const char *merge_rr;
176-
const char *merge_mode;
177-
const char *merge_head;
178-
const char *merge_autostash;
179-
const char *auto_merge;
180-
const char *fetch_head;
181-
const char *shallow;
182-
};
183-
184-
#define PATH_CACHE_INIT { 0 }
185-
186172
const char *git_path_squash_msg(struct repository *r);
187173
const char *git_path_merge_msg(struct repository *r);
188174
const char *git_path_merge_rr(struct repository *r);

repository.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,20 @@ int repo_submodule_init(struct repository *subrepo,
240240
return ret;
241241
}
242242

243+
static void repo_clear_path_cache(struct repo_path_cache *cache)
244+
{
245+
FREE_AND_NULL(cache->squash_msg);
246+
FREE_AND_NULL(cache->squash_msg);
247+
FREE_AND_NULL(cache->merge_msg);
248+
FREE_AND_NULL(cache->merge_rr);
249+
FREE_AND_NULL(cache->merge_mode);
250+
FREE_AND_NULL(cache->merge_head);
251+
FREE_AND_NULL(cache->merge_autostash);
252+
FREE_AND_NULL(cache->auto_merge);
253+
FREE_AND_NULL(cache->fetch_head);
254+
FREE_AND_NULL(cache->shallow);
255+
}
256+
243257
void repo_clear(struct repository *repo)
244258
{
245259
FREE_AND_NULL(repo->gitdir);
@@ -280,6 +294,8 @@ void repo_clear(struct repository *repo)
280294
remote_state_clear(repo->remote_state);
281295
FREE_AND_NULL(repo->remote_state);
282296
}
297+
298+
repo_clear_path_cache(&repo->cached_paths);
283299
}
284300

285301
int repo_read_index(struct repository *repo)

repository.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ struct repo_settings {
4444
int core_multi_pack_index;
4545
};
4646

47+
struct repo_path_cache {
48+
char *squash_msg;
49+
char *merge_msg;
50+
char *merge_rr;
51+
char *merge_mode;
52+
char *merge_head;
53+
char *merge_autostash;
54+
char *auto_merge;
55+
char *fetch_head;
56+
char *shallow;
57+
};
58+
4759
struct repository {
4860
/* Environment */
4961
/*
@@ -82,7 +94,7 @@ struct repository {
8294
/*
8395
* Contains path to often used file names.
8496
*/
85-
struct path_cache cached_paths;
97+
struct repo_path_cache cached_paths;
8698

8799
/*
88100
* Path to the repository's graft file.

0 commit comments

Comments
 (0)