mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
options: don't leak memory when people override options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
005f3826c9
commit
b00525b8c8
3 changed files with 13 additions and 3 deletions
|
@ -4,6 +4,13 @@
|
|||
#include <ccan/tal/str/str.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Override a tal string; frees the old one. */
|
||||
char *opt_set_talstr(const char *arg, char **p)
|
||||
{
|
||||
tal_free(*p);
|
||||
return opt_set_charp(arg, p);
|
||||
}
|
||||
|
||||
static char *default_configdir(const tal_t *ctx)
|
||||
{
|
||||
char *path;
|
||||
|
@ -21,11 +28,11 @@ void configdir_register_opts(const tal_t *ctx,
|
|||
*configdir = default_configdir(ctx);
|
||||
*rpc_filename = "lightning-rpc";
|
||||
|
||||
opt_register_early_arg("--lightning-dir", opt_set_charp, opt_show_charp,
|
||||
opt_register_early_arg("--lightning-dir", opt_set_talstr, opt_show_charp,
|
||||
configdir,
|
||||
"working directory: all other files are relative to this");
|
||||
|
||||
opt_register_arg("--rpc-file", opt_set_charp, opt_show_charp,
|
||||
opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp,
|
||||
rpc_filename,
|
||||
"Set JSON-RPC socket (or /dev/tty)");
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include "config.h"
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
/* Helper for options which are tal() strings. */
|
||||
char *opt_set_talstr(const char *arg, char **p);
|
||||
|
||||
void configdir_register_opts(const tal_t *ctx,
|
||||
char **config_dir, char **rpc_filename);
|
||||
|
||||
|
|
|
@ -523,7 +523,7 @@ void register_opts(struct lightningd *ld)
|
|||
"Print this message.");
|
||||
opt_register_arg("--port", opt_set_u16, opt_show_u16, &ld->portnum,
|
||||
"Port to bind to (0 means don't listen)");
|
||||
opt_register_arg("--bitcoin-datadir", opt_set_charp, NULL,
|
||||
opt_register_arg("--bitcoin-datadir", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->datadir,
|
||||
"-datadir arg for bitcoin-cli");
|
||||
opt_register_arg("--rgb", opt_set_rgb, NULL, ld,
|
||||
|
|
Loading…
Add table
Reference in a new issue