Skip to content

Commit 3a1b5a1

Browse files
committed
refactor(git,store): allocate freshness data through the memory core
The status samples and the stored indexed_checkout_sha were the only new raw malloc/realloc/free sites, which grew the memory-core ratchet (scripts/lint-memory-core.py) for git_context.c and store.c. They now use cbm_alloc/cbm_realloc/cbm_free and cbm_mem_strdup, with one class per pointer (OTHER for the samples, STORE for the column value). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 5c51d71 commit 3a1b5a1

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎src/git/git_context.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "foundation/compat_fs.h"
44
#include "foundation/constants.h"
55
#include "foundation/log.h"
6+
#include "foundation/mem_core.h"
67
#include "foundation/platform.h"
78
#include "foundation/str_util.h"
89

@@ -524,16 +525,17 @@ static void status_add_sample(int *total, char ***samples, int *sample_count,
524525
*truncated = true;
525526
return;
526527
}
527-
char *copy = (char *)malloc(path_len + 1);
528+
char *copy = (char *)cbm_alloc(CBM_MEM_CLASS_OTHER, path_len + 1);
528529
if (!copy) {
529530
*truncated = true;
530531
return;
531532
}
532533
memcpy(copy, path, path_len);
533534
copy[path_len] = '\0';
534-
char **grown = (char **)realloc(*samples, (size_t)(*sample_count + 1) * sizeof(char *));
535+
char **grown = (char **)cbm_realloc(CBM_MEM_CLASS_OTHER, *samples,
536+
(size_t)(*sample_count + 1) * sizeof(char *));
535537
if (!grown) {
536-
free(copy);
538+
cbm_free(CBM_MEM_CLASS_OTHER, copy);
537539
*truncated = true;
538540
return;
539541
}
@@ -668,12 +670,12 @@ void cbm_git_worktree_status_free(cbm_worktree_status_t *st) {
668670
return;
669671
}
670672
for (int i = 0; i < st->tracked_sample_count; i++) {
671-
free(st->tracked_paths[i]);
673+
cbm_free(CBM_MEM_CLASS_OTHER, st->tracked_paths[i]);
672674
}
673-
free(st->tracked_paths);
675+
cbm_free(CBM_MEM_CLASS_OTHER, st->tracked_paths);
674676
for (int i = 0; i < st->untracked_sample_count; i++) {
675-
free(st->untracked_paths[i]);
677+
cbm_free(CBM_MEM_CLASS_OTHER, st->untracked_paths[i]);
676678
}
677-
free(st->untracked_paths);
679+
cbm_free(CBM_MEM_CLASS_OTHER, st->untracked_paths);
678680
memset(st, 0, sizeof(*st));
679681
}

‎src/store/store.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,7 +5072,7 @@ void cbm_store_coverage_meta_clear(cbm_coverage_meta_t *meta) {
50725072
free((char *)meta->index_mode);
50735073
free((char *)meta->recorded_at);
50745074
free((char *)meta->recording_status);
5075-
free((char *)meta->indexed_checkout_sha);
5075+
cbm_free(CBM_MEM_CLASS_STORE, (char *)meta->indexed_checkout_sha);
50765076
memset(meta, 0, sizeof(*meta));
50775077
}
50785078

@@ -5117,7 +5117,8 @@ int cbm_store_coverage_meta_get(cbm_store_t *s, const char *project, cbm_coverag
51175117
out->hash_records_complete = sqlite3_column_int(stmt, 8) != 0;
51185118
if (has_checkout_column) {
51195119
const char *sha = (const char *)sqlite3_column_text(stmt, 9);
5120-
out->indexed_checkout_sha = sha && sha[0] ? heap_strdup(sha) : NULL;
5120+
out->indexed_checkout_sha =
5121+
sha && sha[0] ? cbm_mem_strdup(CBM_MEM_CLASS_STORE, sha) : NULL;
51215122
}
51225123
sqlite3_finalize(stmt);
51235124
if (!out->project || !out->generation || !out->index_mode || !out->recorded_at ||

0 commit comments

Comments
 (0)