diff --git a/plugins/keysend.c b/plugins/keysend.c index afb4c6eba..8d664caab 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -55,7 +55,6 @@ static void keysend_cb(struct keysend_data *d, struct payment *p) { struct route_hop *last_hop; struct createonion_hop *last_payload; size_t hopcount; - u8 *raw_preimage; if (p->step == PAYMENT_STEP_GOT_ROUTE) { /* Force the last step to be a TLV, we might not have an @@ -68,13 +67,10 @@ static void keysend_cb(struct keysend_data *d, struct payment *p) { if (p->step != PAYMENT_STEP_ONION_PAYLOAD) return payment_continue(p); - raw_preimage = tal_dup_arr(p->createonion_request, u8, d->preimage.r, - sizeof(d->preimage), 0); - hopcount = tal_count(p->createonion_request->hops); last_payload = &p->createonion_request->hops[hopcount - 1]; tlvstream_set_raw(&last_payload->tlv_payload->fields, PREIMAGE_TLV_TYPE, - take(raw_preimage)); + &d->preimage, sizeof(struct preimage)); return payment_continue(p); } diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index a06ebc81e..954926d39 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -815,8 +815,10 @@ static void tlvstream_set_tlv_payload_data(struct tlv_field **stream, u8 *ser = tal_arr(NULL, u8, 0); towire_secret(&ser, payment_secret); towire_tu64(&ser, total_msat); - tlvstream_set_raw(stream, TLV_TLV_PAYLOAD_PAYMENT_DATA, take(ser)); + tlvstream_set_raw(stream, TLV_TLV_PAYLOAD_PAYMENT_DATA, ser, tal_bytelen(ser)); + tal_free(ser); } + static void payment_add_hop_onion_payload(struct payment *p, struct createonion_hop *dst, struct route_hop *node, diff --git a/wire/tlvstream.c b/wire/tlvstream.c index 86662f6d5..df96d307a 100644 --- a/wire/tlvstream.c +++ b/wire/tlvstream.c @@ -21,10 +21,10 @@ void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields) } } -void tlvstream_set_raw(struct tlv_field **stream, u64 type, u8 *value TAKES) +void tlvstream_set_raw(struct tlv_field **stream, u64 type, void *value, size_t valuelen) { struct tlv_field f; - f.length = tal_bytelen(value); + f.length = valuelen; f.numtype = type; f.value = tal_dup_arr(*stream, u8, value, f.length, 0); tal_arr_expand(stream, f); @@ -35,21 +35,21 @@ void tlvstream_set_short_channel_id(struct tlv_field **stream, u64 type, { u8 *ser = tal_arr(NULL, u8, 0); towire_short_channel_id(&ser, value); - tlvstream_set_raw(stream, type, take(ser)); + tlvstream_set_raw(stream, type, ser, tal_bytelen(ser)); } void tlvstream_set_tu64(struct tlv_field **stream, u64 type, u64 value) { u8 *ser = tal_arr(NULL, u8, 0); towire_tu64(&ser, value); - tlvstream_set_raw(stream, type, take(ser)); + tlvstream_set_raw(stream, type, ser, tal_bytelen(ser)); } void tlvstream_set_tu32(struct tlv_field **stream, u64 type, u32 value) { u8 *ser = tal_arr(NULL, u8, 0); towire_tu64(&ser, value); - tlvstream_set_raw(stream, type, take(ser)); + tlvstream_set_raw(stream, type, ser, tal_bytelen(ser)); } static struct tlv_field *tlvstream_get_raw(struct tlv_field *stream, u64 type) diff --git a/wire/tlvstream.h b/wire/tlvstream.h index b119c9f5c..4370a8b44 100644 --- a/wire/tlvstream.h +++ b/wire/tlvstream.h @@ -39,7 +39,7 @@ void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields); /* Generic primitive setters for tlvstreams. */ -void tlvstream_set_raw(struct tlv_field **stream, u64 type, u8 *value TAKES); +void tlvstream_set_raw(struct tlv_field **stream, u64 type, void *value, size_t valuelen); void tlvstream_set_short_channel_id(struct tlv_field **stream, u64 type, struct short_channel_id *value); void tlvstream_set_tu64(struct tlv_field **stream, u64 type, u64 value);