mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
Direct leak of 1024 byte(s) in 2 object(s) allocated from: #0 0x7f4c84ce4448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448) #1 0x55d11b782c96 in timer_default_alloc ccan/ccan/timer/timer.c:16 #2 0x55d11b7832b7 in add_level ccan/ccan/timer/timer.c:166 #3 0x55d11b783864 in timer_fast_forward ccan/ccan/timer/timer.c:334 #4 0x55d11b78396a in timers_expire ccan/ccan/timer/timer.c:359 #5 0x55d11b774993 in io_loop ccan/ccan/io/poll.c:395 #6 0x55d11b72322f in plugins_init lightningd/plugin.c:1013 #7 0x55d11b7060ea in main lightningd/lightningd.c:664 #8 0x7f4c84696b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a) To fix this, we actually make 'ld->timers' a pointer, so we can clean it up last of all. We can't free it before ld, because that causes timers to be destroyed. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
36 lines
1 KiB
C
36 lines
1 KiB
C
#include "lightningd/io_loop_with_timers.h"
|
|
|
|
#include <ccan/io/io.h>
|
|
#include <ccan/timer/timer.h>
|
|
#include <common/timeout.h>
|
|
#include <lightningd/lightningd.h>
|
|
#include <wallet/db.h>
|
|
#include <wallet/wallet.h>
|
|
|
|
void *io_loop_with_timers(struct lightningd *ld)
|
|
{
|
|
void *retval = NULL;
|
|
struct timer *expired;
|
|
|
|
while (!retval) {
|
|
/* ~ccan/io's io_loop() continuously calls
|
|
* io_poll_lightningd() for all file descriptors registered
|
|
* with it, then calls their callbacks or closes them if they
|
|
* fail, as appropriate.
|
|
*
|
|
* It will only exit if there's an expired timer, *or* someone
|
|
* calls io_break, or if there are no more file descriptors
|
|
* (which never happens in our code). */
|
|
retval = io_loop(ld->timers, &expired);
|
|
|
|
/*~ Notice that timers are called here in the event loop like
|
|
* anything else, so there are no weird concurrency issues. */
|
|
if (expired) {
|
|
db_begin_transaction(ld->wallet->db);
|
|
timer_expired(ld, expired);
|
|
db_commit_transaction(ld->wallet->db);
|
|
}
|
|
}
|
|
|
|
return retval;
|
|
}
|