From 0a50301d5128a99c58eb79a5afc7b64d3e417a35 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 23 Sep 2020 11:07:04 +0930 Subject: [PATCH] pytest: don't test for memleaks under valgrind. The next patch perturbed things enough that we suddenly started getting (with --track-origins=yes): Valgrind error file: valgrind-errors.120470 ==120470== Use of uninitialised value of size 8 ==120470== at 0x14EBD5: htable_val (htable.c:150) ==120470== by 0x14EC3C: htable_firstval_ (htable.c:165) ==120470== by 0x14F583: htable_del_ (htable.c:349) ==120470== by 0x11825D: pointer_referenced (memleak.c:65) ==120470== by 0x118485: scan_for_pointers (memleak.c:121) ==120470== by 0x118500: memleak_remove_region (memleak.c:130) ==120470== by 0x118A30: call_memleak_helpers (memleak.c:257) ==120470== by 0x118A8B: call_memleak_helpers (memleak.c:262) ==120470== by 0x118A8B: call_memleak_helpers (memleak.c:262) ==120470== by 0x118B25: memleak_find_allocations (memleak.c:278) ==120470== by 0x10EB12: closing_dev_memleak (closingd.c:584) ==120470== by 0x10F3E2: main (closingd.c:783) ==120470== Uninitialised value was created by a heap allocation ==120470== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==120470== by 0x1604E8: allocate (tal.c:250) ==120470== by 0x160AA9: tal_alloc_ (tal.c:428) ==120470== by 0x119BE0: new_per_peer_state (per_peer_state.c:24) ==120470== by 0x11A101: fromwire_per_peer_state (per_peer_state.c:95) ==120470== by 0x10FB7C: fromwire_closingd_init (closingd_wiregen.c:103) ==120470== by 0x10ED15: main (closingd.c:626) ==120470== This is because there is uninitialized padding at the end of struct peer_state. Signed-off-by: Rusty Russell --- common/memleak.c | 10 ++++++---- contrib/pyln-testing/pyln/testing/utils.py | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/memleak.c b/common/memleak.c index 13e336996..03a7d96c3 100644 --- a/common/memleak.c +++ b/common/memleak.c @@ -256,11 +256,13 @@ struct htable *memleak_enter_allocations(const tal_t *ctx, struct htable *memtable = tal(ctx, struct htable); htable_init(memtable, hash_ptr, NULL); - /* First, add all pointers off NULL to table. */ - children_into_htable(exclude1, exclude2, memtable, NULL); + if (memleak_track) { + /* First, add all pointers off NULL to table. */ + children_into_htable(exclude1, exclude2, memtable, NULL); - /* Iterate and call helpers to eliminate hard-to-get references. */ - call_memleak_helpers(memtable, NULL); + /* Iterate and call helpers to eliminate hard-to-get references. */ + call_memleak_helpers(memtable, NULL); + } tal_add_destructor(memtable, htable_clear); return memtable; diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 48b0b8a6d..be34ba7f7 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -584,11 +584,13 @@ class LightningNode(object): # Don't run --version on every subdaemon if we're valgrinding and slow. if SLOW_MACHINE and VALGRIND: self.daemon.opts["dev-no-version-checks"] = None - self.daemon.env["LIGHTNINGD_DEV_MEMLEAK"] = "1" if os.getenv("DEBUG_SUBD"): self.daemon.opts["dev-debugger"] = os.getenv("DEBUG_SUBD") if valgrind: self.daemon.env["LIGHTNINGD_DEV_NO_BACKTRACE"] = "1" + else: + # Under valgrind, scanning can access uninitialized mem. + self.daemon.env["LIGHTNINGD_DEV_MEMLEAK"] = "1" if not may_reconnect: self.daemon.opts["dev-no-reconnect"] = None