* Notes:
*
* \li 'target' refers to the same memory as 'source', so 'source'
- * must not be changed while 'target' is still in use.
+ * must not be changed or freed while 'target' is still in use.
*
* \li This call is functionally equivalent to:
*
isc_result_t
dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target);
-void
-dns_name_copynf(const dns_name_t *source, dns_name_t *dest);
/*%<
- * Makes 'dest' refer to a copy of the name in 'source'. The data are either
- * copied to 'target' or in case of dns_name_copynf the dedicated buffer in
- * 'dest'.
+ * Copies the name in 'source' into 'dest'. The name data is copied to
+ * the 'target' buffer, which is then set as the buffer for 'dest'.
*
* Requires:
* \li 'source' is a valid name.
*
- * \li 'dest' is an initialized name with a dedicated buffer.
+ * \li 'dest' is an initialized name.
*
* \li 'target' is an initialized buffer.
*
- * \li Either dest has a dedicated buffer or target != NULL.
- *
* Ensures:
*
*\li On success, the used space in target is updated.
*\li #ISC_R_NOSPACE
*/
+void
+dns_name_copynf(const dns_name_t *source, dns_name_t *dest);
+/*%<
+ * Copies the name in 'source' into 'dest'. The name data is copied to
+ * the dedicated buffer for 'dest'.
+ *
+ * Requires:
+ * \li 'source' is a valid name.
+ *
+ * \li 'dest' is an initialized name with a dedicated buffer.
+ */
+
bool
dns_name_ishostname(const dns_name_t *name, bool wildcard);
/*%<
static isc_result_t
name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
- unsigned char *ndata;
+ unsigned char *ndata = NULL;
/*
* Make dest a copy of source.
}
if (dest->labels > 0 && dest->offsets != NULL) {
- if (source->offsets != NULL) {
+ if (source->offsets != NULL && source->labels != 0) {
memmove(dest->offsets, source->offsets, source->labels);
} else {
set_offsets(dest, dest->offsets, NULL);
dns_message_takebuffer(msg, &tmprdatabuf);
RETERR(dns_message_gettempname(msg, &newname));
- dns_name_clone(name, newname);
+ dns_name_copynf(name, newname);
RETERR(dns_message_gettemprdatalist(msg, &newlist));
newlist->rdclass = newrdata->rdclass;
if (ret != ISC_R_SUCCESS) {
goto cleanup_rdata;
}
- dns_name_clone(&key->name, owner);
+ dns_name_copynf(&key->name, owner);
ret = dns_message_gettemprdatalist(msg, &datalist);
if (ret != ISC_R_SUCCESS) {
RUNTIME_CHECK(result == ISC_R_SUCCESS);
dns_rdata_reset(&rdata);
- dns_name_clone(&cname.cname, tname);
+ dns_name_copynf(&cname.cname, tname);
dns_rdata_freestruct(&cname);
ns_client_qnamereplace(qctx->client, tname);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
dns_rdata_reset(&rdata);
- dns_name_clone(&cname.cname, tname);
+ dns_name_copynf(&cname.cname, tname);
dns_rdata_freestruct(&cname);
ns_client_qnamereplace(qctx->client, tname);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
dns_rdata_reset(&rdata);
- dns_name_clone(&dname.dname, tname);
+ dns_name_copynf(&dname.dname, tname);
dns_rdata_freestruct(&dname);
/*
if (result != ISC_R_SUCCESS) {
return (result);
}
- dns_name_clone(client->query.qname, aname);
+
+ dns_name_copynf(client->query.qname, aname);
result = dns_message_gettemprdatalist(client->message, &rdatalist);
if (result != ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS) {
return (result);
}
+
+ /*
+ * We'll be releasing 'name' before returning, so it's safe to
+ * use clone instead of copying here.
+ */
dns_name_clone(dns_db_origin(qctx->db), name);
+
rdataset = ns_client_newrdataset(client);
if (rdataset == NULL) {
CTRACE(ISC_LOG_ERROR, "unable to allocate rdataset");