From 2443d45b47d2a0c0e51e8f0b51085b9ddd3cfd00 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 18 Jan 2018 14:25:43 +1030 Subject: [PATCH] delinvoice: fixes. Error code is inverted (which makes sense: who returns 'true' on error?), and anyway there's a leak if we do error. Signed-off-by: Rusty Russell --- lightningd/invoice.c | 8 +++----- wallet/invoices.c | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lightningd/invoice.c b/lightningd/invoice.c index eb94c548d..f0d597f22 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -279,7 +279,6 @@ static void json_delinvoice(struct command *cmd, struct json_result *response = new_json_result(cmd); const char *label; struct wallet *wallet = cmd->ld->wallet; - bool error; if (!json_get_params(buffer, params, "label", &labeltok, @@ -300,10 +299,9 @@ static void json_delinvoice(struct command *cmd, * otherwise the invoice will be freed. */ json_add_invoice(response, i, true); - error = wallet_invoice_delete(wallet, i); - - if (error) { - log_broken(cmd->ld->log, "Error attempting to remove invoice %"PRIu64, + if (!wallet_invoice_delete(wallet, i)) { + log_broken(cmd->ld->log, + "Error attempting to remove invoice %"PRIu64, i->id); command_fail(cmd, "Database error"); return; diff --git a/wallet/invoices.c b/wallet/invoices.c index cef555102..5703f102c 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -230,8 +230,10 @@ bool invoices_delete(struct invoices *invoices, sqlite3_bind_int64(stmt, 1, invoice->id); db_exec_prepared(invoices->db, stmt); - if (sqlite3_changes(invoices->db->sql) != 1) + if (sqlite3_changes(invoices->db->sql) != 1) { + tal_free(tmpctx); return false; + } /* Delete from invoices object. */ list_del_from(&invoices->invlist, &invoice->list);