reftable: introduce REFTABLE_FREE_AND_NULL()
We have several calls to `FREE_AND_NULL()` in the reftable library, which of course uses free(3P). As the reftable allocators are pluggable we should rather call the reftable specific function, which is `reftable_free()`. Introduce a new macro `REFTABLE_FREE_AND_NULL()` and adapt the callsites accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
daa59e9c43
commit
24e0ade65b
@@ -71,6 +71,7 @@ char *reftable_strdup(const char *str);
|
||||
REFTABLE_REALLOC_ARRAY(x, alloc); \
|
||||
} \
|
||||
} while (0)
|
||||
#define REFTABLE_FREE_AND_NULL(p) do { reftable_free(p); (p) = NULL; } while (0)
|
||||
|
||||
/* Find the longest shared prefix size of `a` and `b` */
|
||||
struct strbuf;
|
||||
|
||||
@@ -551,9 +551,9 @@ done:
|
||||
void block_writer_release(struct block_writer *bw)
|
||||
{
|
||||
deflateEnd(bw->zstream);
|
||||
FREE_AND_NULL(bw->zstream);
|
||||
FREE_AND_NULL(bw->restarts);
|
||||
FREE_AND_NULL(bw->compressed);
|
||||
REFTABLE_FREE_AND_NULL(bw->zstream);
|
||||
REFTABLE_FREE_AND_NULL(bw->restarts);
|
||||
REFTABLE_FREE_AND_NULL(bw->compressed);
|
||||
strbuf_release(&bw->last_key);
|
||||
/* the block is not owned. */
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ void reftable_iterator_destroy(struct reftable_iterator *it)
|
||||
return;
|
||||
it->ops->close(it->iter_arg);
|
||||
it->ops = NULL;
|
||||
FREE_AND_NULL(it->iter_arg);
|
||||
REFTABLE_FREE_AND_NULL(it->iter_arg);
|
||||
}
|
||||
|
||||
int reftable_iterator_seek_ref(struct reftable_iterator *it,
|
||||
|
||||
@@ -68,6 +68,6 @@ int merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry
|
||||
|
||||
void merged_iter_pqueue_release(struct merged_iter_pqueue *pq)
|
||||
{
|
||||
FREE_AND_NULL(pq->heap);
|
||||
REFTABLE_FREE_AND_NULL(pq->heap);
|
||||
memset(pq, 0, sizeof(*pq));
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ void reftable_reader_decref(struct reftable_reader *r)
|
||||
if (--r->refcount)
|
||||
return;
|
||||
block_source_close(&r->source);
|
||||
FREE_AND_NULL(r->name);
|
||||
REFTABLE_FREE_AND_NULL(r->name);
|
||||
reftable_free(r);
|
||||
}
|
||||
|
||||
|
||||
@@ -476,8 +476,8 @@ static void reftable_obj_record_key(const void *r, struct strbuf *dest)
|
||||
static void reftable_obj_record_release(void *rec)
|
||||
{
|
||||
struct reftable_obj_record *obj = rec;
|
||||
FREE_AND_NULL(obj->hash_prefix);
|
||||
FREE_AND_NULL(obj->offsets);
|
||||
REFTABLE_FREE_AND_NULL(obj->hash_prefix);
|
||||
REFTABLE_FREE_AND_NULL(obj->offsets);
|
||||
memset(obj, 0, sizeof(struct reftable_obj_record));
|
||||
}
|
||||
|
||||
@@ -834,10 +834,10 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
|
||||
if (val_type != r->value_type) {
|
||||
switch (r->value_type) {
|
||||
case REFTABLE_LOG_UPDATE:
|
||||
FREE_AND_NULL(r->value.update.message);
|
||||
REFTABLE_FREE_AND_NULL(r->value.update.message);
|
||||
r->value.update.message_cap = 0;
|
||||
FREE_AND_NULL(r->value.update.email);
|
||||
FREE_AND_NULL(r->value.update.name);
|
||||
REFTABLE_FREE_AND_NULL(r->value.update.email);
|
||||
REFTABLE_FREE_AND_NULL(r->value.update.name);
|
||||
break;
|
||||
case REFTABLE_LOG_DELETION:
|
||||
break;
|
||||
|
||||
@@ -203,7 +203,7 @@ void reftable_stack_destroy(struct reftable_stack *st)
|
||||
|
||||
err = read_lines(st->list_file, &names);
|
||||
if (err < 0) {
|
||||
FREE_AND_NULL(names);
|
||||
REFTABLE_FREE_AND_NULL(names);
|
||||
}
|
||||
|
||||
if (st->readers) {
|
||||
@@ -224,7 +224,7 @@ void reftable_stack_destroy(struct reftable_stack *st)
|
||||
}
|
||||
strbuf_release(&filename);
|
||||
st->readers_len = 0;
|
||||
FREE_AND_NULL(st->readers);
|
||||
REFTABLE_FREE_AND_NULL(st->readers);
|
||||
}
|
||||
|
||||
if (st->list_fd >= 0) {
|
||||
@@ -232,8 +232,8 @@ void reftable_stack_destroy(struct reftable_stack *st)
|
||||
st->list_fd = -1;
|
||||
}
|
||||
|
||||
FREE_AND_NULL(st->list_file);
|
||||
FREE_AND_NULL(st->reftable_dir);
|
||||
REFTABLE_FREE_AND_NULL(st->list_file);
|
||||
REFTABLE_FREE_AND_NULL(st->reftable_dir);
|
||||
reftable_free(st);
|
||||
free_names(names);
|
||||
}
|
||||
|
||||
@@ -593,7 +593,7 @@ static void object_record_free(void *void_arg UNUSED, void *key)
|
||||
{
|
||||
struct obj_index_tree_node *entry = key;
|
||||
|
||||
FREE_AND_NULL(entry->offsets);
|
||||
REFTABLE_FREE_AND_NULL(entry->offsets);
|
||||
strbuf_release(&entry->hash);
|
||||
reftable_free(entry);
|
||||
}
|
||||
@@ -709,7 +709,7 @@ static void writer_clear_index(struct reftable_writer *w)
|
||||
{
|
||||
for (size_t i = 0; w->index && i < w->index_len; i++)
|
||||
strbuf_release(&w->index[i].last_key);
|
||||
FREE_AND_NULL(w->index);
|
||||
REFTABLE_FREE_AND_NULL(w->index);
|
||||
w->index_len = 0;
|
||||
w->index_cap = 0;
|
||||
}
|
||||
|
||||
@@ -1149,7 +1149,7 @@ static void unclean_stack_close(struct reftable_stack *st)
|
||||
for (size_t i = 0; i < st->readers_len; i++)
|
||||
reftable_reader_decref(st->readers[i]);
|
||||
st->readers_len = 0;
|
||||
FREE_AND_NULL(st->readers);
|
||||
REFTABLE_FREE_AND_NULL(st->readers);
|
||||
}
|
||||
|
||||
static void t_reftable_stack_compaction_concurrent_clean(void)
|
||||
|
||||
Reference in New Issue
Block a user