Skip to content

Commit b5be9ab

Browse files
committed
allow stealing of name buffer
1 parent a927a04 commit b5be9ab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib/unlang/xlat_alloc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ xlat_exp_t *_xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t ty
190190
*/
191191
void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len)
192192
{
193+
fr_assert(node->fmt != fmt);
194+
193195
if (node->fmt) talloc_const_free(node->fmt);
194196
node->fmt = talloc_bstrndup(node, fmt, len);
195197
}
@@ -201,7 +203,13 @@ void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len)
201203
*/
202204
void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt)
203205
{
204-
if (node->fmt) talloc_const_free(node->fmt);
206+
if (node->fmt) {
207+
if (node->fmt == fmt) {
208+
(void) talloc_steal(node, fmt);
209+
} else {
210+
talloc_const_free(node->fmt);
211+
}
212+
}
205213
node->fmt = talloc_typed_strdup_buffer(node, fmt);
206214
}
207215

@@ -212,6 +220,8 @@ void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt)
212220
*/
213221
void xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt)
214222
{
223+
fr_assert(node->fmt != fmt);
224+
215225
if (node->fmt) talloc_const_free(node->fmt);
216226
node->fmt = talloc_get_type_abort_const(fmt, char);
217227
}

0 commit comments

Comments
 (0)