Skip to content
Snippets Groups Projects
Commit 137a1309 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

knot_rrset_shallow_copy(): do not modify output when error occurs

CID: 1086926
parent 04c36d45
No related branches found
No related tags found
No related merge requests found
......@@ -1325,17 +1325,24 @@ int knot_rrset_deep_copy(const knot_rrset_t *from, knot_rrset_t **to)
int knot_rrset_shallow_copy(const knot_rrset_t *from, knot_rrset_t **to)
{
*to = (knot_rrset_t *)malloc(sizeof(knot_rrset_t));
CHECK_ALLOC_LOG(*to, KNOT_ENOMEM);
if (!from || !to) {
return KNOT_EINVAL;
}
memcpy(*to, from, sizeof(knot_rrset_t));
knot_rrset_t *result = (knot_rrset_t *)malloc(sizeof(knot_rrset_t));
if (!result) {
return KNOT_ENOMEM;
}
/* Retain owner. */
(*to)->owner = knot_dname_copy((*to)->owner);
if ((*to)->owner == NULL) {
memcpy(result, from, sizeof(knot_rrset_t));
result->owner = knot_dname_copy(result->owner);
if (!result->owner) {
free(result);
return KNOT_ENOMEM;
}
*to = result;
return KNOT_EOK;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment