utils: add a global tmpctx.

I did a brief audit of tmpctx uses, and we do leak them in various
corner cases.  Fortunely, all our daemons are based on some kind of
I/O loop, so it's fairly easy to clean a global tmpctx at that point.

This makes things a bit neater, and slightly more efficient, but also
clearer: I avoided creating a tmpctx in a few places because I didn't
want to add another allocation.  With that penalty removed, I can use
it more freely and hopefully write clearer code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-03-15 15:00:37 +10:30
parent 41ef42ee94
commit ef2a063169
10 changed files with 38 additions and 40 deletions

View File

@@ -1,5 +1,4 @@
#define SUPERVERBOSE
static void *tmpctx;
#include <assert.h>
#include <ccan/str/hex/hex.h>
@@ -23,7 +22,7 @@ int main(void)
struct secret base_secret, per_commitment_secret;
struct pubkey base_point, per_commitment_point, pubkey, pubkey2;
tmpctx = tal_tmpctx(NULL);
setup_tmpctx();
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);