db/postgres: avoid memleak.

```
"label": "db/db_postgres.c:294:char[]",
"backtrace": [
  "ccan/ccan/tal/tal.c:442 (tal_alloc_)",
  "ccan/ccan/tal/tal.c:471 (tal_alloc_arr_)",
  "ccan/ccan/tal/str/str.c:91 (tal_vfmt_)",
  "ccan/ccan/tal/str/str.c:44 (tal_fmt_)",
  "db/db_postgres.c:294 (db_postgres_delete_columns)",
  "wallet/db.c:1546 (migrate_payments_scids_as_integers)",
  "wallet/db.c:986 (db_migrate)",
  "wallet/db.c:1019 (db_setup)",
  "wallet/wallet.c:101 (wallet_new)",
  "lightningd/lightningd.c:1023 (main)",
  "../csu/libc-start.c:308 (__libc_start_main)"
],
"parents": [
  "db/utils.c:317:struct db",
  "lightningd/lightningd.c:107:struct lightningd"
]
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-09-19 10:24:26 +09:30 committed by Christian Decker
parent f52ff07558
commit 939a7b2b18

View file

@ -291,7 +291,7 @@ static bool db_postgres_delete_columns(struct db *db,
{ {
char *cmd; char *cmd;
cmd = tal_fmt(db, "ALTER TABLE %s ", tablename); cmd = tal_fmt(tmpctx, "ALTER TABLE %s ", tablename);
for (size_t i = 0; i < num_cols; i++) { for (size_t i = 0; i < num_cols; i++) {
if (i != 0) if (i != 0)
tal_append_fmt(&cmd, ", "); tal_append_fmt(&cmd, ", ");