aboutsummaryrefslogtreecommitdiff
path: root/bp.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-08-01 15:36:53 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-08-01 15:36:53 -0700
commit0b2de4721f3dcf95d6d0af54c78e197df10f6666 (patch)
tree7b64cefb5c2897510fffdb6c1aa36c792a4c61c4 /bp.c
parent8268e67875abeaae99d0793e424514662a84628d (diff)
Moved caching code onto the file, which fixed an issue with file slicing
having stale cache values.
Diffstat (limited to 'bp.c')
-rw-r--r--bp.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bp.c b/bp.c
index 6dec579..9f20241 100644
--- a/bp.c
+++ b/bp.c
@@ -406,7 +406,7 @@ static int process_file(def_t *defs, const char *filename, pat_t *pattern)
}
fflush(stdout);
- cache_destroy();
+ cache_destroy(f);
if (recycle_all_matches() != 0)
fprintf(stderr, "\033[33;1mMemory leak: there should no longer be any matches in use at this point.\033[0m\n");
destroy_file(&f);
@@ -624,6 +624,10 @@ int main(int argc, char *argv[])
tty_out = fopen("/dev/tty", "w");
}
+ // No need for these caches anymore:
+ for (file_t *f = loaded_files; f; f = f->next)
+ cache_destroy(f);
+
int found = 0;
if (options.mode == MODE_JSON) printf("[");
if (options.git_mode) { // Get the list of files from `git --ls-files ...`
@@ -652,7 +656,6 @@ int main(int argc, char *argv[])
// This code frees up all residual heap-allocated memory. Since the program
// is about to exit, this step is unnecessary. However, it is useful for
// tracking down memory leaks.
- cache_destroy();
free_all_matches();
defs = free_defs(defs, NULL);
while (loaded_files) {