void *tal_memdup(const tal_t *ctx, const void *p, size_t n)
{
- void *ret = tal_arr(ctx, char, n);
+ void *ret;
+
+ if (ctx == TAL_TAKE)
+ return (void *)p;
+
+ ret = tal_arr(ctx, char, n);
if (ret)
memcpy(ret, p, n);
return ret;
char *tal_vasprintf(const tal_t *ctx, const char *fmt, va_list ap)
{
size_t max = strlen(fmt) * 2;
- char *buf = tal_arr(ctx, char, max);
+ char *buf;
int ret;
+ if (ctx == TAL_TAKE)
+ buf = tal_arr(tal_parent(fmt), char, max);
+ else
+ buf = tal_arr(ctx, char, max);
+
while (buf) {
va_list ap2;
break;
buf = tal_resize(buf, max *= 2);
}
+ if (ctx == TAL_TAKE)
+ tal_free(fmt);
return buf;
}