Skip to content

Commit d275270

Browse files
committed
do not use lyd_value()
1 parent f21bdb7 commit d275270

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/plugins_types/union.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,13 @@ lyb_parse_union(const void *lyb_data, size_t lyb_data_len, uint32_t *type_idx, c
153153
/**
154154
* @brief For leafref failures, ensure the appropriate error is propagated, not a type validation failure.
155155
*
156-
* @param[in] ctx_node Context node for prefix resolution.
157156
* @param[in,out] err Error record to be updated
158157
* @param[in] type leafref type used to extract target path
159158
* @param[in] value value attempting to be stored
160159
* @param[in] value_len Length of value that was attempted to be stored.
161160
*/
162161
static void
163-
union_update_lref_err(const struct lyd_node *ctx_node, struct ly_err_item *err, const struct lysc_type *type, const void *value, size_t value_len)
162+
union_update_lref_err(struct ly_err_item *err, const struct lysc_type *type, const void *value, size_t value_len)
164163
{
165164
const struct lysc_type_leafref *lref;
166165
char *valstr = NULL;
@@ -174,12 +173,7 @@ union_update_lref_err(const struct lyd_node *ctx_node, struct ly_err_item *err,
174173
err->apptag = strdup("instance-required");
175174

176175
free(err->msg);
177-
178-
if (lyd_get_value(ctx_node) != NULL) {
179-
valstr = strdup(lyd_get_value(ctx_node));
180-
} else {
181-
valstr = strndup((const char *)value, value_len);
182-
}
176+
valstr = strndup((const char *)value, value_len);
183177
asprintf(&err->msg, LY_ERRMSG_NOLREF_VAL, valstr, lyxp_get_expr(lref->path));
184178
free(valstr);
185179
}
@@ -226,8 +220,8 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
226220
memset(&subvalue->value, 0, sizeof subvalue->value);
227221

228222
/* if this is a leafref, lets make sure we propagate the appropriate error, and not a type validation failure */
229-
union_update_lref_err(ctx_node, *err, type_u->types[ti], value, value_len);
230-
return rc;
223+
union_update_lref_err(*err, type_u->types[ti], value, value_len);
224+
goto cleanup;
231225
}
232226

233227
assert(subvalue->value.realtype);
@@ -256,9 +250,6 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
256250
if (options & LYPLG_TYPE_STORE_ONLY) {
257251
opts |= LYPLG_TYPE_STORE_ONLY;
258252
}
259-
if (dynamic) {
260-
opts |= LYPLG_TYPE_STORE_DYNAMIC;
261-
}
262253

263254
rc = type->plugin->store(ctx, type, value, value_len, opts, format, prefix_data, subvalue->hints,
264255
subvalue->ctx_node, &subvalue->value, unres, err);
@@ -267,8 +258,8 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
267258
memset(&subvalue->value, 0, sizeof subvalue->value);
268259

269260
/* if this is a leafref, lets make sure we propagate the appropriate error, and not a type validation failure */
270-
union_update_lref_err(ctx_node, *err, type, value, value_len);
271-
return rc;
261+
union_update_lref_err(*err, type, value, value_len);
262+
goto cleanup;
272263
}
273264

274265
if (validate && (rc == LY_EINCOMPLETE)) {
@@ -280,6 +271,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
280271
}
281272
}
282273

274+
cleanup:
275+
if (dynamic) {
276+
free((void *)value);
277+
}
283278
return rc;
284279
}
285280

0 commit comments

Comments
 (0)