mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-12-27 09:04:40 +01:00
68043c2e8c
valgrind locally complains about the allocations in autodata leaking: ``` ==138200== 16 bytes in 1 blocks are still reachable in loss record 1 of 2 ==138200== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==138200== by 0x10D41A: autodata_register_ (autodata.c:20) ==138200== by 0x10E7B8: register_autotype_type_to_string (type_to_string.h:79) ==138200== by 0x10F5CA: register_one_type_to_string0 (block.c:259) ==138200== by 0x19734C: __libc_csu_init (in /home/rusty/devel/cvs/lightning/common/test/run-route-specific) ==138200== by 0x4A3D03F: (below main) (libc-start.c:264) ==138200== ==138200== 176 bytes in 1 blocks are still reachable in loss record 2 of 2 ==138200== at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==138200== by 0x10D472: autodata_register_ (autodata.c:26) ==138200== by 0x122D37: register_autotype_type_to_string (type_to_string.h:79) ==138200== by 0x122F1F: register_one_type_to_string0 (node_id.c:50) ==138200== by 0x19734C: __libc_csu_init (in /home/rusty/devel/cvs/lightning/common/test/run-route-specific) ==138200== by 0x4A3D03F: (below main) (libc-start.c:264) ==138200== make: *** [Makefile:638: unittest/common/test/run-route-specific] Error 7 ``` Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
64 lines
1.4 KiB
C
64 lines
1.4 KiB
C
#include "config.h"
|
|
#include <assert.h>
|
|
#include <ccan/ccan/err/err.h>
|
|
#include <common/autodata.h>
|
|
#include <common/setup.h>
|
|
#include <common/utils.h>
|
|
#include <sodium.h>
|
|
#include <wally_core.h>
|
|
|
|
static void *wally_tal(size_t size)
|
|
{
|
|
assert(wally_tal_ctx);
|
|
return tal_arr_label(wally_tal_ctx, u8, size, "wally_tal");
|
|
}
|
|
|
|
static void wally_free(void *ptr)
|
|
{
|
|
tal_free(ptr);
|
|
}
|
|
|
|
static struct wally_operations wally_tal_ops = {
|
|
.struct_size = sizeof(struct wally_operations),
|
|
.malloc_fn = wally_tal,
|
|
.free_fn = wally_free,
|
|
};
|
|
|
|
|
|
void common_setup(const char *argv0)
|
|
{
|
|
int wally_ret;
|
|
|
|
setup_locale();
|
|
err_set_progname(argv0);
|
|
|
|
/* We rely on libsodium for some of the crypto stuff, so we'd better
|
|
* not start if it cannot do its job correctly. */
|
|
if (sodium_init() == -1)
|
|
errx(1, "Could not initialize libsodium. Maybe not enough entropy"
|
|
" available ?");
|
|
|
|
/* We set up Wally, the bitcoin wallet lib */
|
|
wally_ret = wally_init(0);
|
|
if (wally_ret != WALLY_OK)
|
|
errx(1, "Error initializing libwally: %i", wally_ret);
|
|
wally_ret = wally_set_operations(&wally_tal_ops);
|
|
if (wally_ret != WALLY_OK)
|
|
errx(1, "Error setting libwally operations: %i", wally_ret);
|
|
secp256k1_ctx = wally_get_secp_context();
|
|
|
|
setup_tmpctx();
|
|
}
|
|
|
|
void common_shutdown(void)
|
|
{
|
|
const char *p = taken_any();
|
|
if (p)
|
|
errx(1, "outstanding taken(): %s", p);
|
|
take_cleanup();
|
|
tal_free(tmpctx);
|
|
wally_cleanup(0);
|
|
tal_free(wally_tal_ctx);
|
|
autodata_cleanup();
|
|
}
|