Commit cd5eb191 authored by Marek Vavruša's avatar Marek Vavruša

mm: mm_alloc/mm_free replaces direct use

parent 7171fb37
...@@ -342,7 +342,7 @@ size_t hattrie_weight (const hattrie_t *T) ...@@ -342,7 +342,7 @@ size_t hattrie_weight (const hattrie_t *T)
hattrie_t* hattrie_create_n(unsigned bucket_size, const mm_ctx_t *mm) hattrie_t* hattrie_create_n(unsigned bucket_size, const mm_ctx_t *mm)
{ {
hattrie_t* T = mm->alloc(mm->ctx, sizeof(hattrie_t)); hattrie_t* T = mm_alloc((mm_ctx_t *)mm, sizeof(hattrie_t));
memcpy(&T->mm, mm, sizeof(mm_ctx_t)); memcpy(&T->mm, mm, sizeof(mm_ctx_t));
hattrie_init(T, bucket_size); hattrie_init(T, bucket_size);
return T; return T;
......
...@@ -218,7 +218,7 @@ hhash_t *hhash_create_mm(uint32_t size, const mm_ctx_t *mm) ...@@ -218,7 +218,7 @@ hhash_t *hhash_create_mm(uint32_t size, const mm_ctx_t *mm)
} }
const size_t total_len = sizeof(hhash_t) + size * sizeof(hhelem_t); const size_t total_len = sizeof(hhash_t) + size * sizeof(hhelem_t);
hhash_t *tbl = mm->alloc(mm->ctx, total_len); hhash_t *tbl = mm_alloc((mm_ctx_t *)mm, total_len);
if (tbl) { if (tbl) {
memset(tbl, 0, total_len); memset(tbl, 0, total_len);
tbl->size = size; tbl->size = size;
......
...@@ -132,7 +132,7 @@ static int axfr_query_init(struct query_data *qdata) ...@@ -132,7 +132,7 @@ static int axfr_query_init(struct query_data *qdata)
mm_ctx_t *mm = qdata->mm; mm_ctx_t *mm = qdata->mm;
zone_contents_t *zone = qdata->zone->contents; zone_contents_t *zone = qdata->zone->contents;
struct axfr_proc *axfr = mm->alloc(mm->ctx, sizeof(struct axfr_proc)); struct axfr_proc *axfr = mm_alloc(mm, sizeof(struct axfr_proc));
if (axfr == NULL) { if (axfr == NULL) {
return KNOT_ENOMEM; return KNOT_ENOMEM;
} }
...@@ -187,7 +187,7 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb process_item, ...@@ -187,7 +187,7 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb process_item,
if (ret == KNOT_EOK) { /* Finished. */ if (ret == KNOT_EOK) { /* Finished. */
/* Complete change set. */ /* Complete change set. */
rem_node((node_t *)head); rem_node((node_t *)head);
mm->free(head); mm_free(mm, head);
} else { /* Packet full or other error. */ } else { /* Packet full or other error. */
break; break;
} }
......
...@@ -51,7 +51,7 @@ static int wildcard_visit(struct query_data *qdata, const zone_node_t *node, con ...@@ -51,7 +51,7 @@ static int wildcard_visit(struct query_data *qdata, const zone_node_t *node, con
} }
mm_ctx_t *mm = qdata->mm; mm_ctx_t *mm = qdata->mm;
struct wildcard_hit *item = mm->alloc(mm->ctx, sizeof(struct wildcard_hit)); struct wildcard_hit *item = mm_alloc(mm, sizeof(struct wildcard_hit));
item->node = node; item->node = node;
item->sname = sname; item->sname = sname;
add_tail(&qdata->wildcards, (node_t *)item); add_tail(&qdata->wildcards, (node_t *)item);
......
...@@ -202,7 +202,7 @@ static void ixfr_answer_cleanup(struct query_data *qdata) ...@@ -202,7 +202,7 @@ static void ixfr_answer_cleanup(struct query_data *qdata)
ptrlist_free(&ixfr->proc.nodes, mm); ptrlist_free(&ixfr->proc.nodes, mm);
changeset_iter_clear(&ixfr->cur); changeset_iter_clear(&ixfr->cur);
changesets_free(&ixfr->changesets); changesets_free(&ixfr->changesets);
mm->free(qdata->ext); mm_free(mm, qdata->ext);
/* Allow zone changes (finished). */ /* Allow zone changes (finished). */
rcu_read_unlock(); rcu_read_unlock();
...@@ -233,7 +233,7 @@ static int ixfr_answer_init(struct query_data *qdata) ...@@ -233,7 +233,7 @@ static int ixfr_answer_init(struct query_data *qdata)
/* Initialize transfer processing. */ /* Initialize transfer processing. */
mm_ctx_t *mm = qdata->mm; mm_ctx_t *mm = qdata->mm;
struct ixfr_proc *xfer = mm->alloc(mm->ctx, sizeof(struct ixfr_proc)); struct ixfr_proc *xfer = mm_alloc(mm, sizeof(struct ixfr_proc));
if (xfer == NULL) { if (xfer == NULL) {
changesets_free(&chgsets); changesets_free(&chgsets);
return KNOT_ENOMEM; return KNOT_ENOMEM;
......
...@@ -176,7 +176,7 @@ static knot_pkt_t *pkt_new_mm(void *wire, uint16_t len, mm_ctx_t *mm) ...@@ -176,7 +176,7 @@ static knot_pkt_t *pkt_new_mm(void *wire, uint16_t len, mm_ctx_t *mm)
{ {
assert(mm); assert(mm);
knot_pkt_t *pkt = mm->alloc(mm->ctx, sizeof(knot_pkt_t)); knot_pkt_t *pkt = mm_alloc(mm, sizeof(knot_pkt_t));
if (pkt == NULL) { if (pkt == NULL) {
return NULL; return NULL;
} }
...@@ -185,7 +185,7 @@ static knot_pkt_t *pkt_new_mm(void *wire, uint16_t len, mm_ctx_t *mm) ...@@ -185,7 +185,7 @@ static knot_pkt_t *pkt_new_mm(void *wire, uint16_t len, mm_ctx_t *mm)
pkt->rrset_count = 0; pkt->rrset_count = 0;
memcpy(&pkt->mm, mm, sizeof(mm_ctx_t)); memcpy(&pkt->mm, mm, sizeof(mm_ctx_t));
if (pkt_reset(pkt, wire, len) != KNOT_EOK) { if (pkt_reset(pkt, wire, len) != KNOT_EOK) {
mm->free(pkt); mm_free(mm, pkt);
return NULL; return NULL;
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
static void *mm_realloc(mm_ctx_t *mm, void *what, size_t size, size_t prev_size) static void *mm_realloc(mm_ctx_t *mm, void *what, size_t size, size_t prev_size)
{ {
if (mm) { if (mm) {
void *p = mm->alloc(mm->ctx, size); void *p = mm_alloc(mm, size);
if (knot_unlikely(p == NULL)) { if (knot_unlikely(p == NULL)) {
return NULL; return NULL;
} else { } else {
...@@ -33,9 +33,8 @@ static void *mm_realloc(mm_ctx_t *mm, void *what, size_t size, size_t prev_size) ...@@ -33,9 +33,8 @@ static void *mm_realloc(mm_ctx_t *mm, void *what, size_t size, size_t prev_size)
memcpy(p, what, memcpy(p, what,
prev_size < size ? prev_size : size); prev_size < size ? prev_size : size);
} }
if (mm->free) {
mm->free(what); mm_free(mm, what);
}
return p; return p;
} }
} else { } else {
......
...@@ -32,7 +32,7 @@ static const char *alphabet = "0123abcdABCDwxyzWXYZ.-_"; ...@@ -32,7 +32,7 @@ static const char *alphabet = "0123abcdABCDwxyzWXYZ.-_";
char *test_randstr_mm(struct mm_ctx *mm) char *test_randstr_mm(struct mm_ctx *mm)
{ {
unsigned len = (5 + rand() % 251) + 1; unsigned len = (5 + rand() % 251) + 1;
char *s = mm->alloc(mm->ctx, len * sizeof(char)); char *s = mm_alloc(mm, len * sizeof(char));
for (unsigned i = 0; i < len - 1; ++i) { for (unsigned i = 0; i < len - 1; ++i) {
s[i] = alphabet[rand() % strlen(alphabet)]; s[i] = alphabet[rand() % strlen(alphabet)];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment