Memory leak due to theme reinitiation #4

Closed
opened 2025-06-20 15:41:08 +00:00 by jabber.developer · 0 comments

Commit 6034b833be introduced a call to theme_init(theme) after entering the PGP key password. However, this introduces two issues:

  1. The call may be unnecessary in this context, as no visual redrawing occurs — only preference loading.
  2. It introduces a potential memory leak.

The function theme_init(const char* const theme_name) includes the following line:

defaults = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);

Because there is no check for an existing defaults table, any previously allocated hash table is silently overwritten. If _theme_close() is not called beforehand, this results in a memory leak.

This behavior is problematic, as it makes it easy to introduce memory leaks simply by invoking theme_init() repeatedly without proper cleanup.

  • Add explicit support for theme reinitialization, including proper cleanup and logging.
  • Ensure any existing hash tables are freed or reused appropriately inside theme_init().
  • Consider removing the theme_init() call from sv_ev_roster_received, as it appears unnecessary for this code path and contributes to inefficiency and resource leaks.
Commit 6034b833be introduced a call to `theme_init(theme)` after entering the PGP key password. However, this introduces two issues: 1. The call may be unnecessary in this context, as no visual redrawing occurs — only preference loading. 2. It introduces a potential memory leak. The function `theme_init(const char* const theme_name)` includes the following line: https://git.jabber.space/devs/profanity/src/commit/ddc4290c990cd3941d324d9b8ae9ed1f99bc9a46/src/config/theme.c#L104 Because there is no check for an existing `defaults` table, any previously allocated hash table is silently overwritten. If `_theme_close()` is not called beforehand, this results in a memory leak. This behavior is problematic, as it makes it easy to introduce memory leaks simply by invoking `theme_init()` repeatedly without proper cleanup. ### Recommended Fix - Add explicit support for theme reinitialization, including proper cleanup and logging. - Ensure any existing hash tables are freed or reused appropriately inside `theme_init()`. - Consider removing the `theme_init()` call from `sv_ev_roster_received`, as it appears unnecessary for this code path and contributes to inefficiency and resource leaks.
admin closed this issue 2025-06-24 15:37:12 +00:00
jabber.developer self-assigned this 2025-09-01 22:23:52 +00:00
jabber.developer added the
Kind/Bug
label 2025-09-01 22:24:55 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: devs/cproof#4
No description provided.