From 97fd81b60b8d87dfb63597aa67ca855729b20591 Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Thu, 21 May 2026 15:34:33 +0300 Subject: [PATCH] fix(review): address F1, F6, F9, F16 from deep review - src/log.c (F16): log_stderr_init no longer closes STDERR_FILENO immediately after dup2(). The previous 'close(dup_fd)' closed fd 2 because dup2 returns newfd on success; the in-app stderr capture pipe was silently dead, dropping libstrophe/openssl error output. Close the original stderr_pipe[1] instead and remember that the write end now lives at STDERR_FILENO so _log_stderr_close stays correct. - src/database_sqlite.c (F1): NULL-check sqlite3_mprintf result before passing it to sqlite3_exec in the DbVersion bootstrap path. - src/tools/editor.c (F9): drop three orphan #includes (, , ) left behind when 9b03e3a50 removed the async-editor path. - src/xmpp/jid.c (F6): match the g_new0 allocation in jid_create with g_free in jid_destroy. Same behaviour on glibc but stops being a foot-gun under custom glib allocators. Verified with ci-build.sh in Debian docker: all 4 configs pass (644/0, 605/0, 605/0, 644/0 unit + 130/0 functional). --- src/database_sqlite.c | 4 ++++ src/log.c | 7 ++++--- src/tools/editor.c | 5 +---- src/xmpp/jid.c | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/database_sqlite.c b/src/database_sqlite.c index e479e618..9af82bc4 100644 --- a/src/database_sqlite.c +++ b/src/database_sqlite.c @@ -232,6 +232,10 @@ _sqlite_init(ProfAccount* account) auto_sqlite char* init_version_query = sqlite3_mprintf( "INSERT INTO `DbVersion` (`version`) VALUES (%d) ON CONFLICT(`version`) DO NOTHING", latest_version); + if (!init_version_query) { + log_error("OOM allocating initial DbVersion insert query"); + goto out; + } if (SQLITE_OK != sqlite3_exec(g_chatlog_database, init_version_query, NULL, 0, &err_msg)) { goto out; } diff --git a/src/log.c b/src/log.c index 3117167a..ea526926 100644 --- a/src/log.c +++ b/src/log.c @@ -348,10 +348,11 @@ log_stderr_init(log_level_t level) goto err_free; } - int dup_fd = dup2(stderr_pipe[1], STDERR_FILENO); - if (dup_fd < 0) + if (dup2(stderr_pipe[1], STDERR_FILENO) < 0) goto err_free; - close(dup_fd); + // fd 2 now owns the pipe write end; release the original. + close(stderr_pipe[1]); + stderr_pipe[1] = STDERR_FILENO; stderr_level = level; stderr_inited = 1; diff --git a/src/tools/editor.c b/src/tools/editor.c index 5fbbc871..98b0be71 100644 --- a/src/tools/editor.c +++ b/src/tools/editor.c @@ -9,14 +9,11 @@ * SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception */ -#include #include #include -#include // necessary for readline -#include +#include #include #include -#include #include #include "config/files.h" diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index ccedcb3e..8b7dbbdf 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -217,7 +217,7 @@ jid_destroy(Jid* jid) g_free(jid->resourcepart); g_free(jid->barejid); g_free(jid->fulljid); - free(jid); + g_free(jid); } gboolean