diff --git a/bitcoin/base58.c b/bitcoin/base58.c index 70f2689cd..28d3db746 100644 --- a/bitcoin/base58.c +++ b/bitcoin/base58.c @@ -24,13 +24,12 @@ static char *to_base58(const tal_t *ctx, u8 version, buf[0] = version; memcpy(buf + 1, rmd, sizeof(*rmd)); - if (wally_base58_from_bytes((const unsigned char *) buf, total_length, BASE58_FLAG_CHECKSUM, &out) != WALLY_OK) { - return NULL; - }else{ - char *res = tal_strdup(ctx, out); - wally_free_string(out); - return res; - } + if (wally_base58_from_bytes((const unsigned char *) buf, + total_length, BASE58_FLAG_CHECKSUM, &out) + != WALLY_OK) + out = NULL; + + return tal_steal(ctx, out); } char *bitcoin_to_base58(const tal_t *ctx, const struct chainparams *chainparams, diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 1551e198a..d9d48689c 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -645,15 +645,13 @@ struct wally_psbt *psbt_from_b64(const tal_t *ctx, char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt) { - char *serialized_psbt, *ret_val; + char *serialized_psbt; int ret; ret = wally_psbt_to_base64(psbt, 0, &serialized_psbt); assert(ret == WALLY_OK); - ret_val = tal_strdup(ctx, serialized_psbt); - wally_free_string(serialized_psbt); - return ret_val; + return tal_steal(ctx, serialized_psbt); } REGISTER_TYPE_TO_STRING(wally_psbt, psbt_to_b64);