Skip to content

Conversation

@Andezion
Copy link

@Andezion Andezion commented Jan 9, 2026

(Fixes #8802 )

Problem

When building with Clang and sanitizers enabled on Ubuntu 24.04, LeakSanitizer detects 1392 bytes of leaked memory in the sql plugin during init_tablemap():

Solution

Added a destroy_sql() destructor function that calls strmap_clear(&sql->tablemap) to properly free the internal strmap tree nodes. The destructor is registered with tal_add_destructor(sql, destroy_sql) in main(). Destructor to clean up strmap internal nodes.

Note: table_desc structures are tal-allocated as children of plugin context,
so they're freed automatically. This only cleans up the strmap tree overhead.

static void destroy_sql(struct sql *sql)
{
    strmap_clear(&sql->tablemap);
}

This ensures all memory is properly freed when the sql plugin terminates, resolving the LeakSanitizer errors.

Changelog
Fixed: Memory leak in sql plugin - freed strmap internal nodes on plugin cleanup (1392 bytes)

Important

26.04 FREEZE March 11th: Non-bugfix PRs not ready by this date will wait for 26.06.

RC1 is scheduled on March 23rd

The final release is scheduled for April 15th.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure: LeakSanitizer detects memory leaks in plugins/sql.c (init_tablemap())

1 participant