plugins: Fix undefined deallocation order in struct plugins

We use the new function `plugins_free` to define the correct deallocation
order on shutdown, since under normal operation the allocation tree is
organized to allow plugins to terminate and automatically free all dependent
resources. During shutdown the deallocation order is under-defined since
siblings may get freed in any order, but we implicitly rely on them staying
around.
This commit is contained in:
Christian Decker
2020-04-12 15:42:41 +02:00
committed by Rusty Russell
parent 284bd7de0c
commit 27ea47ae37
4 changed files with 37 additions and 1 deletions

View File

@@ -56,6 +56,19 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
return p;
}
void plugins_free(struct plugins *plugins)
{
struct plugin *p;
/* Plugins are usually the unit of allocation, and they are internally
* consistent, so let's free each plugin first. */
while (!list_empty(&plugins->plugins)) {
p = list_pop(&plugins->plugins, struct plugin, list);
tal_free(p);
}
tal_free(plugins);
}
static void destroy_plugin(struct plugin *p)
{
struct plugin_rpccall *call;