Commit 6d738bf3 authored by Marek Vavrusa's avatar Marek Vavrusa

Implemented refcounting to server.

* Node and rrset now must use new API for changing owner (*_set_owner())
* Every structure that stores pointer to dname must retain reference to it
* Destructors in rrset now release all stored dnames, obsoletes parameters: free_owner
* Destructor in rdata_deep_free has obsolete parameter: free_all_dnames
* Fixed some direct data manipulation
* Some code readability improvements
* To do:
 * Reference counting in zparser is disabled for now, implement correctly.
 * Remove obsolete parameters.
 * Destructors should have no extra parameters.
* Tested with server startup, querying and AXFR client/server

Commit refs #993.
parent 7f36b49f
......@@ -4,18 +4,25 @@
void ref_init(ref_t *p, ref_destructor_t dtor)
{
p->count = 0;
p->dtor = dtor;
if (p) {
p->count = 0;
p->dtor = dtor;
}
}
void ref_retain(ref_t *p)
{
__sync_add_and_fetch(&p->count, 1);
if (p) {
__sync_add_and_fetch(&p->count, 1);
}
}
void ref_release(ref_t *p)
{
if (__sync_sub_and_fetch(&p->count, 1) <= 0) {
p->dtor(p);
if (p) {
int rc = __sync_sub_and_fetch(&p->count, 1);
if (rc == 0) {
p->dtor(p);
}
}
}
......@@ -135,6 +135,9 @@ dnslib_dname_t *dnslib_dname_table_find_dname(const dnslib_dname_table_t *table,
if (node == NULL) {
return NULL;
} else {
/* Increase reference counter. */
dnslib_dname_retain(node->dname);
return node->dname;
}
}
......@@ -171,7 +174,6 @@ int dnslib_dname_table_add_dname2(dnslib_dname_table_t *table,
dnslib_dname_t **dname)
{
dnslib_dname_t *found_dname = NULL;
int ret;
if (table == NULL || dname == NULL || *dname == NULL) {
return DNSLIB_EBADARG;
......@@ -181,22 +183,31 @@ int dnslib_dname_table_add_dname2(dnslib_dname_table_t *table,
// printf("Inserting name %s to dname table.\n", name);
// free(name);
if ((!(found_dname =
dnslib_dname_table_find_dname(table ,*dname))) &&
(ret = dnslib_dname_table_add_dname(table, *dname))
!= DNSLIB_EOK) {
// printf("Error!\n");
return ret;
} else if (found_dname != NULL && found_dname != *dname) {
/* Fetch dname, need to release it later. */
found_dname = dnslib_dname_table_find_dname(table ,*dname);
if (!found_dname) {
/* Store reference in table. */
return dnslib_dname_table_add_dname(table, *dname);
} else {
/*! \todo Remove the check for equality. */
// name = dnslib_dname_to_str(found_dname);
// printf("Already there: %s (%p)\n", name, found_dname);
// free(name);
/*! \todo Release or free? We didn't retain it, so why release? */
dnslib_dname_release(*dname);
*dname = found_dname;
return 1;
if (found_dname != *dname) {
//name = dnslib_dname_to_str(found_dname);
//printf("Already there: %s (%p)\n", name, found_dname);
//free(name);
/* Replace dname with found. */
dnslib_dname_release(*dname);
*dname = found_dname;
return 1; /*! \todo Error code? */
} else {
/* If the dname is already in the table, there is already
* a reference to it.
*/
dnslib_dname_release(found_dname);
}
}
// printf("Done.\n");
......
......@@ -55,6 +55,9 @@ dnslib_dname_table_t *dnslib_dname_table_new();
/*!
* \brief Finds name in the domain name table.
*
* \note Reference count to dname will be incremented, caller is responsible
* for releasing it.
*
* \param table Domain name table to be searched.
* \param dname Dname to be searched.
*
......
......@@ -373,6 +373,14 @@ static inline void dnslib_dname_retain(dnslib_dname_t *dname) {
}
}
/*
#define dnslib_dname_retain(d) \
dnslib_dname_retain_((d));\
if ((d))\
fprintf(stderr, "dname_retain: %s() at %s:%d, %p refcount=%zu\n",\
__func__, __FILE__, __LINE__, d, (d)->ref.count)
*/
/*!
* \brief Decrement reference counter for dname.
*
......@@ -383,6 +391,13 @@ static inline void dnslib_dname_release(dnslib_dname_t *dname) {
ref_release(&dname->ref);
}
}
/*
#define dnslib_dname_release(d) \
if ((d))\
fprintf(stderr, "dname_release: %s() at %s:%d, %p refcount=%zu\n",\
__func__, __FILE__, __LINE__, d, (d)->ref.count-1);\
dnslib_dname_release_((d))
*/
#endif /* _KNOT_DNSLIB_DNAME_H_ */
......
......@@ -170,6 +170,8 @@ dnslib_node_t *dnslib_node_new(dnslib_dname_t *owner, dnslib_node_t *parent,
return NULL;
}
/* Store reference to owner. */
dnslib_dname_retain(owner);
ret->owner = owner;
dnslib_node_set_parent(ret, parent);
ret->rrsets = skip_create_list(compare_rrset_types);
......@@ -434,6 +436,18 @@ dnslib_dname_t *dnslib_node_get_owner(const dnslib_node_t *node)
/*----------------------------------------------------------------------------*/
void dnslib_node_set_owner(dnslib_node_t *node, dnslib_dname_t* owner)
{
if (node) {
/* Retain new owner and release old owner. */
dnslib_dname_retain(owner);
dnslib_dname_release(node->owner);
node->owner = owner;
}
}
/*----------------------------------------------------------------------------*/
const dnslib_node_t *dnslib_node_wildcard_child(const dnslib_node_t *node,
int check_version)
{
......@@ -697,10 +711,12 @@ void dnslib_node_free(dnslib_node_t **node, int free_owner, int fix_refs)
debug_dnslib_node("Freeing RRSets.\n");
skip_destroy_list(&(*node)->rrsets, NULL, NULL);
}
if (free_owner) {
debug_dnslib_node("Freeing owner.\n");
/*! \todo Always release owner? */
//if (free_owner) {
debug_dnslib_node("Releasing owner.\n");
dnslib_dname_release((*node)->owner);
}
//}
// check nodes referencing this node and fix the references
......
......@@ -106,6 +106,8 @@ typedef enum {
/*!
* \brief Creates and initializes new node structure.
*
* \todo Owner reference counter will be increased.
*
* \param owner Owner of the created node.
* \param parent Parent of the created node.
* \param flags Document me.
......@@ -272,8 +274,21 @@ void dnslib_node_set_nsec3_node(dnslib_node_t *node, dnslib_node_t *nsec3_node);
*/
const dnslib_dname_t *dnslib_node_owner(const dnslib_node_t *node);
/*!
* \todo Document me.
*/
dnslib_dname_t *dnslib_node_get_owner(const dnslib_node_t *node);
/*!
* \brief Set node owner to specified dname.
*
* Previous owner will be replaced if exist.
*
* \param node Specified node.
* \param owner New owner dname.
*/
void dnslib_node_set_owner(dnslib_node_t *node, dnslib_dname_t* owner);
/*!
* \brief Returns the wildcard child of the node.
*
......
......@@ -399,8 +399,12 @@ DEBUG_DNSLIB_PACKET(
uint32_t ttl = dnslib_wire_read_u32(wire + *pos + 4);
dnslib_rrset_t *rrset = dnslib_rrset_new(owner, type, rclass, ttl);
/* Owner is either referenced in rrset or rrset creation failed. */
dnslib_dname_release(owner);
/* Check rrset allocation. */
if (rrset == NULL) {
dnslib_dname_release(owner);
return NULL;
}
......@@ -415,7 +419,6 @@ DEBUG_DNSLIB_PACKET(
if (size - *pos < rdlength) {
debug_dnslib_packet("Malformed RR: Not enough data to parse RR"
" RDATA.\n");
//dnslib_dname_free(&rrset->owner);
dnslib_rrset_deep_free(&rrset, 1, 1, 0);
// free(rrset);
return NULL;
......@@ -433,7 +436,6 @@ DEBUG_DNSLIB_PACKET(
dnslib_rrtype_descriptor_by_type(rrset->type));
if (rdata == NULL) {
debug_dnslib_packet("Malformed RR: Could not parse RDATA.\n");
//dnslib_dname_free(&rrset->owner);
dnslib_rrset_deep_free(&rrset, 1, 1, 0);
// free(rrset);
return NULL;
......@@ -442,7 +444,6 @@ DEBUG_DNSLIB_PACKET(
if (dnslib_rrset_add_rdata(rrset, rdata) != DNSLIB_EOK) {
debug_dnslib_packet("Malformed RR: Could not add RDATA to RRSet"
".\n");
//dnslib_dname_free(&rrset->owner);
dnslib_rdata_free(&rdata);
dnslib_rrset_deep_free(&rrset, 1, 1, 0);
// free(rrset);
......
......@@ -201,6 +201,7 @@ int dnslib_rdata_from_wire(dnslib_rdata_t *rdata, const uint8_t *wire,
//*pos += dname->size;
parsed += pos2 - *pos;
*pos = pos2;
dname = 0;
break;
case DNSLIB_RDATA_WF_BYTE:
// printf("Next item - byte.\n");
......@@ -266,6 +267,7 @@ int dnslib_rdata_from_wire(dnslib_rdata_t *rdata, const uint8_t *wire,
//*pos += dname->size;
parsed += pos2 - *pos;
*pos = pos2;
dname = 0;
break;
default:
assert(0);
......@@ -317,6 +319,11 @@ int dnslib_rdata_set_item(dnslib_rdata_t *rdata, uint pos,
if (pos >= rdata->count) {
return DNSLIB_EBADARG;
}
/*! \todo As in set_items() we should increment refcounter for dnames,
* but we don't know the item type.
*/
rdata->items[pos] = item; // this should copy the union; or use memcpy?
return DNSLIB_EOK;
}
......@@ -348,6 +355,10 @@ int dnslib_rdata_set_items(dnslib_rdata_t *rdata,
memcpy(rdata->items, items, count * sizeof(dnslib_rdata_item_t));
rdata->count = count;
/*! \todo Cannot determine items type, so the dname
* refcounters should be increased in caller.
*/
return DNSLIB_EOK;
}
......@@ -384,6 +395,9 @@ int dnslib_rdata_item_set_dname(dnslib_rdata_t *rdata, uint pos,
return DNSLIB_EBADARG;
}
/* Retain dname. */
dnslib_dname_retain(dname);
rdata->items[pos].dname = dname;
return DNSLIB_EOK;
......@@ -440,9 +454,17 @@ void dnslib_rdata_deep_free(dnslib_rdata_t **rdata, uint type,
if (desc->wireformat[i] == DNSLIB_RDATA_WF_COMPRESSED_DNAME
|| desc->wireformat[i] == DNSLIB_RDATA_WF_UNCOMPRESSED_DNAME
|| desc->wireformat[i] == DNSLIB_RDATA_WF_LITERAL_DNAME ) {
if (((*rdata)->items[i].dname != NULL) &&
free_all_dnames) {
dnslib_dname_release((*rdata)->items[i].dname);
if (((*rdata)->items[i].dname != NULL)) {
/*! \todo This is hack to prevent memory errors,
* as the rdata_set_items() cannot determine
* items type and so cannot increment
* reference count in case of dname type.
* Free would then release dnames that
* aren't referenced by the rdata.
*/
if (free_all_dnames) {
dnslib_dname_release((*rdata)->items[i].dname);
}
}
} else {
free((*rdata)->items[i].raw_data);
......
......@@ -54,6 +54,9 @@ dnslib_rrset_t *dnslib_rrset_new(dnslib_dname_t *owner, uint16_t type,
ret->rdata = NULL;
/* Retain reference to owner. */
dnslib_dname_retain(owner);
ret->owner = owner;
ret->type = type;
ret->rclass = rclass;
......@@ -179,6 +182,18 @@ dnslib_dname_t *dnslib_rrset_get_owner(const dnslib_rrset_t *rrset)
/*----------------------------------------------------------------------------*/
void dnslib_rrset_set_owner(dnslib_rrset_t *rrset, dnslib_dname_t* owner)
{
if (rrset) {
/* Retain new owner and release old owner. */
dnslib_dname_retain(owner);
dnslib_dname_release(rrset->owner);
rrset->owner = owner;
}
}
/*----------------------------------------------------------------------------*/
uint16_t dnslib_rrset_type(const dnslib_rrset_t *rrset)
{
return rrset->type;
......@@ -307,6 +322,9 @@ void dnslib_rrset_free(dnslib_rrset_t **rrset)
return;
}
/*! \todo Shouldn't we always release owner reference? */
dnslib_dname_release((*rrset)->owner);
free(*rrset);
*rrset = NULL;
}
......@@ -344,9 +362,10 @@ void dnslib_rrset_deep_free(dnslib_rrset_t **rrset, int free_owner,
free_rdata_dnames);
}
if (free_owner) {
/*! \todo Release owner every time? */
//if (free_owner) {
dnslib_dname_release((*rrset)->owner);
}
//}
free(*rrset);
*rrset = NULL;
......
......@@ -116,8 +116,21 @@ int dnslib_rrset_add_rrsigs(dnslib_rrset_t *rrset, dnslib_rrset_t *rrsigs,
*/
const dnslib_dname_t *dnslib_rrset_owner(const dnslib_rrset_t *rrset);
/*!
* \todo Document me.
*/
dnslib_dname_t *dnslib_rrset_get_owner(const dnslib_rrset_t *rrset);
/*!
* \brief Set rrset owner to specified dname.
*
* Previous owner will be replaced if exist.
*
* \param rrset Specified RRSet.
* \param owner New owner dname.
*/
void dnslib_rrset_set_owner(dnslib_rrset_t *rrset, dnslib_dname_t* owner);
/*!
* \brief Returns the TYPE of the RRSet.
*
......
......@@ -723,8 +723,7 @@ static int dnslib_zone_contents_dnames_from_rrset_to_table(
if (replace_owner) {
// discard the old owner and replace it with the new
//dnslib_dname_free(&rrset->owner);
rrset->owner = owner;
dnslib_rrset_set_owner(rrset, owner);
}
debug_dnslib_zone("RRSet owner: %p\n", rrset->owner);
......@@ -1004,6 +1003,8 @@ DEBUG_DNSLIB_ZONE(
dnslib_zone_contents_dnames_from_node_to_table(
zone->dname_table, next_node);
if (ret != DNSLIB_EOK) {
/*! \todo Will next_node leak? */
dnslib_dname_release(chopped);
return ret;
}
}
......@@ -1027,7 +1028,7 @@ DEBUG_DNSLIB_ZONE(
"to zone tree.\n");
/*! \todo Delete the node?? */
/* Directly discard. */
dnslib_dname_free(&chopped);
dnslib_dname_release(chopped);
return ret;
}
......@@ -1050,7 +1051,7 @@ DEBUG_DNSLIB_ZONE(
"hash table!\n");
/*! \todo Delete the node?? */
/* Directly discard. */
dnslib_dname_free(&chopped);
dnslib_dname_release(chopped);
return DNSLIB_EHASH;
}
......@@ -1068,7 +1069,14 @@ DEBUG_DNSLIB_ZONE(
#endif
debug_dnslib_zone("Next parent.\n");
node = next_node;
dnslib_dname_t *chopped_last = chopped;
chopped = dnslib_dname_left_chop(chopped);
/* Release last chop, reference is already stored
* in next_node.
*/
dnslib_dname_release(chopped_last);
}
// set the found parent (in the zone) as the parent of the last
// inserted node
......@@ -1079,7 +1087,8 @@ DEBUG_DNSLIB_ZONE(
}
/* Directly discard. */
dnslib_dname_free(&chopped);
/*! \todo This may be double-release. */
dnslib_dname_release(chopped);
return DNSLIB_EOK;
}
......@@ -1145,8 +1154,7 @@ int dnslib_zone_contents_add_rrset(dnslib_zone_contents_t *zone,
// table)
/*! \todo Do even if domain table is not used?? */
if (ret == DNSLIB_EOK && rrset->owner != (*node)->owner) {
dnslib_dname_release(rrset->owner);
rrset->owner = (*node)->owner;
dnslib_rrset_set_owner(rrset, (*node)->owner);
}
debug_dnslib_zone("RRSet OK.\n");
......@@ -1252,8 +1260,7 @@ int dnslib_zone_contents_add_rrsigs(dnslib_zone_contents_t *zone,
// replace RRSet's owner with the node's owner (that is already in the
// table)
if ((*rrset)->owner != (*rrset)->rrsigs->owner) {
dnslib_dname_release(rrsigs->owner);
(*rrset)->rrsigs->owner = (*rrset)->owner;
dnslib_rrset_set_owner((*rrset)->rrsigs, (*rrset)->owner);
}
debug_dnslib_zone("RRSIGs OK\n");
......@@ -1365,8 +1372,7 @@ int dnslib_zone_contents_add_nsec3_rrset(dnslib_zone_contents_t *zone,
// table)
/*! \todo Do even if domain table is not used? */
if (rrset->owner != (*node)->owner) {
dnslib_dname_release(rrset->owner);
rrset->owner = (*node)->owner;
dnslib_rrset_set_owner(rrset, (*node)->owner);
}
debug_dnslib_zone("NSEC3 OK\n");
......@@ -2238,7 +2244,8 @@ void dnslib_zone_contents_deep_free(dnslib_zone_contents_t **contents)
dnslib_zone_tree_reverse_apply_postorder(
(*contents)->nsec3_nodes,
dnslib_zone_contents_destroy_node_rrsets_from_tree, 0);
dnslib_zone_contents_destroy_node_rrsets_from_tree,
(void*)1);
dnslib_zone_tree_reverse_apply_postorder(
(*contents)->nsec3_nodes,
......@@ -2246,7 +2253,8 @@ void dnslib_zone_contents_deep_free(dnslib_zone_contents_t **contents)
dnslib_zone_tree_reverse_apply_postorder(
(*contents)->nodes,
dnslib_zone_contents_destroy_node_rrsets_from_tree, 0);
dnslib_zone_contents_destroy_node_rrsets_from_tree,
(void*)1);
dnslib_zone_tree_reverse_apply_postorder(
(*contents)->nodes,
......
......@@ -117,8 +117,25 @@ static void load_rdata_purge(dnslib_rdata_t *rdata,
int count,
uint16_t type)
{
/* Increase refcount manually, as the set_items() doesn't see the dname
* type and thus is unable to increment refcounter.
*/
unsigned i = 0;
switch(type) {
case DNSLIB_RDATA_WF_COMPRESSED_DNAME:
case DNSLIB_RDATA_WF_UNCOMPRESSED_DNAME:
case DNSLIB_RDATA_WF_LITERAL_DNAME:
for (i = 0; i < count; ++i) {
dnslib_dname_retain(items[i].dname);
}
break;
default:
break;
}
/* Copy items to rdata and free the temporary rdata. */
dnslib_rdata_set_items(rdata, items, count);
dnslib_rdata_deep_free(&rdata, type, 0);
dnslib_rdata_deep_free(&rdata, type, 1);
free(items);
}
......@@ -230,6 +247,9 @@ static dnslib_rdata_t *dnslib_load_rdata(uint16_t type, FILE *f,
load_rdata_purge(rdata, items, i, type);
return NULL;
}
/* Store reference do dname. */
dnslib_dname_retain(id_array[dname_id]);
items[i].dname = id_array[dname_id];
} else {
items[i].dname = read_dname_with_id(f);
......@@ -284,6 +304,7 @@ static dnslib_rdata_t *dnslib_load_rdata(uint16_t type, FILE *f,
}
}
/* Each item has refcount already incremented for saving in rdata. */
if (dnslib_rdata_set_items(rdata, items, desc->length) != 0) {
fprintf(stderr, "zoneload: Could not set items "
"when loading rdata.\n");
......@@ -398,6 +419,12 @@ static dnslib_rrset_t *dnslib_load_rrset(FILE *f, dnslib_dname_t **id_array,
rrset = dnslib_rrset_new(owner, rrset_type, rrset_class, rrset_ttl);
if (!use_ids) {
/* Directly release if allocated locally. */
dnslib_dname_release(owner);
owner = 0;
}
debug_dnslib_zload("RRSet type: %d\n", rrset->type);
dnslib_rdata_t *tmp_rdata;
......@@ -418,11 +445,11 @@ static dnslib_rrset_t *dnslib_load_rrset(FILE *f, dnslib_dname_t **id_array,
if (rrsig_count) {
tmp_rrsig = dnslib_load_rrsig(f, id_array, use_ids);
if (!use_ids) {
tmp_rrsig->owner = rrset->owner;
dnslib_rrset_set_owner(tmp_rrsig, rrset->owner);
}
}
rrset->rrsigs = tmp_rrsig;
dnslib_rrset_set_rrsigs(rrset, tmp_rrsig);
return rrset;
}
......@@ -483,7 +510,9 @@ static dnslib_node_t *dnslib_load_node(FILE *f, dnslib_dname_t **id_array)
dnslib_node_set_nsec3_node(node, NULL);
// node->nsec3_node = NULL;
}
node->owner = owner;
/* Retain new owner while releasing replaced owner. */
dnslib_node_set_owner(node, owner);
node->flags = flags;
//XXX will have to be set already...canonical order should do it
......@@ -504,9 +533,10 @@ static dnslib_node_t *dnslib_load_node(FILE *f, dnslib_dname_t **id_array)
fprintf(stderr, "zone: Could not load rrset.\n");
return NULL;
}
tmp_rrset->owner = node->owner;
/* Retain new owner while releasing replaced owner. */
dnslib_rrset_set_owner(tmp_rrset, node->owner);
if (tmp_rrset->rrsigs != NULL) {
tmp_rrset->rrsigs->owner = node->owner;
dnslib_rrset_set_owner(tmp_rrset->rrsigs, node->owner);
}
if (dnslib_node_add_rrset(node, tmp_rrset, 0) < 0) {
fprintf(stderr, "zone: Could not add rrset.\n");
......@@ -834,17 +864,24 @@ static dnslib_dname_t **create_dname_array(FILE *f, uint max_id)
}
if (read_dname->id < max_id) {
/* Create new node from dname. */
read_dname->node = dnslib_node_new(read_dname, NULL, 0);
if (read_dname->node == NULL) {
ERR_ALLOC_FAILED;
cleanup_id_array(array, 0, i);
/* Directly discard. */
dnslib_dname_free(&read_dname);
/* Release read dname. */
dnslib_dname_release(read_dname);
cleanup_id_array(array, 0, i);
return NULL;
}
/* Store reference to dname in array. */
array[read_dname->id] = read_dname;
} else {
/* Release read dname. */
dnslib_dname_release(read_dname);
cleanup_id_array(array, 0, i);
return NULL;
}
......
......@@ -120,8 +120,10 @@ static dnslib_rrset_t *ns_synth_from_wildcard(
dnslib_rrset_class(wildcard_rrset),
dnslib_rrset_ttl(wildcard_rrset));
/* Release owner, as it's retained in rrset. */
dnslib_dname_release(owner);
if (synth_rrset == NULL) {
dnslib_dname_release(owner);
return NULL;
}
......@@ -1425,8 +1427,10 @@ static dnslib_rrset_t *ns_cname_from_dname(const dnslib_rrset_t *dname_rrset,
dnslib_rrset_t *cname_rrset = dnslib_rrset_new(
owner, DNSLIB_RRTYPE_CNAME, DNSLIB_CLASS_IN, SYNTH_CNAME_TTL);
/* Release owner, as it's retained in rrset. */
dnslib_dname_release(owner);
if (cname_rrset == NULL) {
dnslib_dname_release(owner);
return NULL;
}
......
......@@ -52,7 +52,7 @@ static int xfrin_create_query(const dnslib_zone_contents_t *zone, uint16_t qtype
const dnslib_node_t *apex = dnslib_zone_contents_apex(zone);
dnslib_dname_t *qname = dnslib_node_get_owner(apex);
/*! \todo What happens if apex is freed before we lock? */
/* Retain qname until the question is freed. */
dnslib_dname_retain(qname);
// this is ugly!!
......@@ -62,6 +62,7 @@ static int xfrin_create_query(const dnslib_zone_contents_t *zone, uint16_t qtype
rc = dnslib_query_set_question(pkt, &question);
if (rc != DNSLIB_EOK) {
dnslib_dname_release(question.qname);
dnslib_packet_free(&pkt);
return KNOT_ERROR;
}
......@@ -74,6 +75,7 @@ static int xfrin_create_query(const dnslib_zone_contents_t *zone, uint16_t qtype
size_t wire_size = 0;
rc = dnslib_packet_to_wire(pkt, &wire, &wire_size);
if (rc != DNSLIB_EOK) {
dnslib_dname_release(question.qname);
dnslib_packet_free(&pkt);
return KNOT_ERROR;
}
......@@ -94,7 +96,7 @@ static int xfrin_create_query(const dnslib_zone_contents_t *zone, uint16_t qtype
dnslib_packet_free(&pkt);
/* Release qname. */
dnslib_dname_release(qname);
dnslib_dname_release(question.qname);
return KNOT_EOK;
}
......
......@@ -300,6 +300,9 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
dname = dnslib_dname_new_from_str((char *)wireformat,
length,
NULL);
/*! \todo implement refcounting correctly. */
ref_init(&dname->ref, 0); /* disable dtor */
ref_retain(&dname->ref);
if (dname == NULL) {
dbg_rdata("malformed dname!\n");
......@@ -1819,6 +1822,9 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
dnslib_dname_t *dname =
dnslib_dname_new_from_str(name, strlen(name), NULL);
/*! \todo implement refcounting correctly. */
ref_init(&dname->ref, 0); /* disable dtor */
ref_retain(&dname->ref);
dnslib_node_t *origin_node = dnslib_node_new(dname, NULL, 0);
......
......@@ -211,10 +211,13 @@ ANY [^\"\n\\]|\\.
/*! \todo dnslib_dname_new_from_wire() (dname.h)
* which dnslib_node to pass as node?
*/
const dnslib_dname_t *dname;
dnslib_dname_t *dname;
dname = dnslib_dname_new_from_wire((uint8_t*)tmp + 1,
strlen(tmp + 1),
NULL);
/*! \todo implement refcounting correctly. */
ref_init(&dname->ref, 0); /* disable dtor */
ref_retain(&dname->ref);
if (!dname) {
zc_error("incorrect include origin '%s'",
tmp + 1);
......
......@@ -363,6 +363,9 @@ label: STR
$$ = error_dname;
} else {
$$ = dnslib_dname_new_from_str($1.str, $1.len, NULL);
/*! \todo implement refcounting correctly. */
//ref_init(&$$->ref, 0); /* disable dtor */
//ref_retain(&dname->ref);
//printf("new: %p %s\n", $$, dnslib_dname_to_str($$));
}
......@@ -1206,6 +1209,9 @@ rdata_rrsig: STR sp STR sp STR sp STR sp STR sp STR
$15.len));*/
dnslib_dname_t *dname =
dnslib_dname_new_from_wire((uint8_t *)$15.str, $15.len, NULL);
/*! \todo implement refcounting correctly. */
ref_init(&dname->ref, 0); /* disable dtor */
ref_retain(&dname->ref);
dnslib_dname_cat(dname, parser->root_domain);
......@@ -1233,6 +1239,10 @@ rdata_nsec: wire_dname nsec_seq
dnslib_dname_t *dname =
dnslib_dname_new_from_wire((uint8_t *)$1.str, $1.len, NULL);
/*! \todo implement refcounting correctly. */
ref_init(&dname->ref, 0); /* disable dtor */
ref_retain(&dname->ref);
free($1.str);
dnslib_dname_cat(dname, parser->root_domain);
......@@ -1305,7 +1315,7 @@ rdata_dnskey: STR sp STR sp STR sp str_sp_seq trail
rdata_ipsec_base: STR sp STR sp STR sp dotted_str
{
const dnslib_dname_t* name = 0;
dnslib_dname_t* name = 0;
zadd_rdata_wireformat(zparser_conv_byte($1.str)); /* precedence */
zadd_rdata_wireformat(zparser_conv_byte($3.str));
/* gateway type */
......@@ -1328,6 +1338,9 @@ rdata_ipsec_base: STR sp STR sp STR sp dotted_str
name = dnslib_dname_new_from_wire((uint8_t*)$7.str + 1,
strlen($7.str + 1),
NULL);
/*! \todo implement refcounting correctly. */
ref_init(&name->ref, 0); /* disable dtor */
ref_retain(&name->ref);
if(!name) {