Fix some more memory leaks + an invalid read.

`ProfMessage` was not completely initialized, fix this by using `calloc()`
for the allocation.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2025-03-07 11:49:08 +01:00
parent 93fc4ecd8b
commit b55bf6e4bd
6 changed files with 24 additions and 11 deletions

View File

@@ -1647,6 +1647,7 @@ cmd_ac_uninit(void)
autocomplete_free(plugins_unload_ac);
autocomplete_free(plugins_reload_ac);
autocomplete_free(script_show_ac);
g_hash_table_destroy(ac_funcs);
}
static void

View File

@@ -169,6 +169,7 @@ otr_start_query(void)
static void
_otr_shutdown(void)
{
g_hash_table_destroy(smp_initiators);
if (jid) {
free(jid);
jid = NULL;

View File

@@ -57,9 +57,19 @@ static int _block_remove_result_handler(xmpp_stanza_t* const stanza, void* const
static GList* blocked;
static Autocomplete blocked_ac;
static void
_blocking_shutdown(void)
{
if (blocked) {
g_list_free_full(blocked, free);
}
autocomplete_free(blocked_ac);
}
void
blocking_request(void)
{
prof_add_shutdown_routine(_blocking_shutdown);
if (blocked) {
g_list_free_full(blocked, free);
blocked = NULL;

View File

@@ -66,9 +66,19 @@ static int _bookmark_result_id_handler(xmpp_stanza_t* const stanza, void* const
static void _bookmark_destroy(Bookmark* bookmark);
static void _send_bookmarks(void);
static void
_bookmark_shutdown(void)
{
if (bookmarks) {
g_hash_table_destroy(bookmarks);
}
autocomplete_free(bookmark_ac);
}
void
bookmark_request(void)
{
prof_add_shutdown_routine(_bookmark_shutdown);
if (bookmarks) {
g_hash_table_destroy(bookmarks);
}

View File

@@ -72,6 +72,7 @@ static EntityCapabilities* _caps_copy(EntityCapabilities* caps);
static void
_caps_close(void)
{
caps_reset_ver();
free_keyfile(&caps_prof_keyfile);
cache = NULL;
g_hash_table_destroy(jid_to_ver);

View File

@@ -347,19 +347,9 @@ message_handlers_init(void)
ProfMessage*
message_init(void)
{
ProfMessage* message = malloc(sizeof(ProfMessage));
ProfMessage* message = calloc(1, sizeof(ProfMessage));
message->from_jid = NULL;
message->to_jid = NULL;
message->id = NULL;
message->originid = NULL;
message->stanzaid = NULL;
message->replace_id = NULL;
message->body = NULL;
message->encrypted = NULL;
message->plain = NULL;
message->enc = PROF_MSG_ENC_NONE;
message->timestamp = NULL;
message->trusted = true;
message->type = PROF_MSG_TYPE_UNINITIALIZED;