v0.0.65 - Release: fix segfault in settings sync — dispatch merge to main thread via g_idle_add to avoid data race on g_settings

This commit is contained in:
Laan Tungir
2026-08-01 05:35:10 -04:00
parent c7aa7b5c37
commit 95a32b5548
3 changed files with 29 additions and 5 deletions
+1 -1
View File
@@ -1 +1 @@
0.0.64
0.0.65
+26 -2
View File
@@ -28,6 +28,10 @@
#define MAX_RELAYS 32
/* Relay query timeout in seconds. */
/* Forward declaration — defined below. */
static gboolean merge_settings_idle(gpointer data);
#define RELAY_TIMEOUT_SECONDS 15
/* Forward declaration — defined after relay_fetch_bootstrap. */
@@ -120,11 +124,18 @@ int relay_fetch_bootstrap(const char *pubkey_hex,
/* Store in SQLite first, then try to merge into local settings.
* settings_sync_merge_from_nostr checks the d-tag and only
* merges if it's the shared "user-settings" event (or the
* legacy "sovereign_browser" event, which is migrated). */
* legacy "sovereign_browser" event, which is migrated).
*
* IMPORTANT: The merge calls settings_load() which writes to
* the global g_settings struct. This must run on the main
* thread to avoid a data race with the GTK main loop. */
if (db_store_event(results[i]) == 0) {
stored++;
}
settings_sync_merge_from_nostr(results[i]);
cJSON *event_copy = cJSON_Duplicate(results[i], 1);
if (event_copy) {
g_idle_add(merge_settings_idle, event_copy);
}
} else {
if (db_store_event(results[i]) == 0) {
stored++;
@@ -208,6 +219,19 @@ static gboolean avatar_refresh_idle(gpointer data) {
return G_SOURCE_REMOVE;
}
/* Idle callback to merge NIP-78 settings on the main thread.
* settings_sync_merge_from_nostr calls settings_load() which writes to
* the global g_settings struct, so it must run on the GTK main thread
* to avoid data races with the main loop. Takes ownership of event_cjson. */
static gboolean merge_settings_idle(gpointer data) {
cJSON *event = (cJSON *)data;
if (event) {
settings_sync_merge_from_nostr(event);
cJSON_Delete(event);
}
return FALSE; /* run once */
}
/* ── Background thread ─────────────────────────────────────────────── */
gpointer relay_fetch_thread(gpointer data) {
+2 -2
View File
@@ -11,9 +11,9 @@
#ifndef SOVEREIGN_BROWSER_VERSION_H
#define SOVEREIGN_BROWSER_VERSION_H
#define SB_VERSION "v0.0.64"
#define SB_VERSION "v0.0.65"
#define SB_VERSION_MAJOR 0
#define SB_VERSION_MINOR 0
#define SB_VERSION_PATCH 64
#define SB_VERSION_PATCH 65
#endif /* SOVEREIGN_BROWSER_VERSION_H */