From 4f3085740149e9024965a8c3c932344a6a76a4fc Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Wed, 12 Apr 2023 17:25:06 -0500 Subject: [PATCH] lightningd: close plugin dir on return Memory leak detected by ASan: ==880002==ERROR: LeakSanitizer: detected memory leaks Direct leak of 32816 byte(s) in 1 object(s) allocated from: #0 0x5039e7 in malloc (lightningd/lightningd+0x5039e7) #1 0x7f2e8c203884 in __alloc_dir (/lib64/libc.so.6+0xd2884) --- lightningd/plugin.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 81a936a30..d7ad4707e 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1703,9 +1703,11 @@ char *add_plugin_dir(struct plugins *plugins, const char *dir, bool error_ok) } else { p = plugin_register(plugins, fullpath, NULL, false, NULL, NULL); - if (!p && !error_ok) + if (!p && !error_ok) { + closedir(d); return tal_fmt(NULL, "Failed to register %s: %s", fullpath, strerror(errno)); + } } } closedir(d);