ipv6-address REFACTOR dup cleanup fixed
Fixes
@@ -310,26 +310,25 @@ lyplg_type_dup_ipv6_address(const struct ly_ctx *ctx, const struct lyd_value *or
LY_ERR ret;
struct lyd_value_ipv6_address *orig_val, *dup_val;
+ memset(dup, 0, sizeof *dup);
+
ret = lydict_insert(ctx, original->_canonical, ly_strlen(original->_canonical), &dup->_canonical);
LY_CHECK_RET(ret);
LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
- if (!dup_val) {
- lydict_remove(ctx, dup->_canonical);
- return LY_EMEM;
- }
+ LY_CHECK_ERR_GOTO(!dup_val, ret = LY_EMEM, error);
LYD_VALUE_GET(original, orig_val);
memcpy(&dup_val->addr, &orig_val->addr, sizeof orig_val->addr);
ret = lydict_insert(ctx, orig_val->zone, 0, &dup_val->zone);
- if (ret) {
- lydict_remove(ctx, dup->_canonical);
- free(dup_val);
- return ret;
- }
+ LY_CHECK_GOTO(ret, error);
dup->realtype = original->realtype;
return LY_SUCCESS;
+
+error:
+ lyplg_type_free_ipv6_address(ctx, dup);
+ return ret;
}
/**
