From b8056cbf24eea5121d362ea3757b10d0dfe21652 Mon Sep 17 00:00:00 2001 From: Bakkeby Date: Thu, 29 Jan 2026 21:28:16 +0100 Subject: [PATCH] xresources: destroy Xrm database after resource load st would hold on to a XrmDatabase reference for the lifetime of the program due to how in resource_load the ret.addr of the database would be referenced directly. This also meant that for every reload st would be leaking another XrmDatabase reference. This has been partially worked around by applying a strdup to make a copy of the string in order to allow for the XrmDatabase to be freed / destroyed. Consequently the char arrays / strings still leak on reload. We could pass *sdst to free beforehand, but that will only work if that reference is guaranteed to be on the heap. --- patch/xresources.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/patch/xresources.c b/patch/xresources.c index 5617b1a..acdad4d 100644 --- a/patch/xresources.c +++ b/patch/xresources.c @@ -22,7 +22,8 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) switch (rtype) { case STRING: - *sdst = ret.addr; + /* Note: this leaks memory */ + *sdst = strdup(ret.addr); break; case INTEGER: *idst = strtoul(ret.addr, NULL, 10); @@ -47,8 +48,13 @@ config_init(Display *dpy) return; db = XrmGetStringDatabase(resm); + if (!db) + return; + for (p = resources; p < resources + LEN(resources); p++) resource_load(db, p->name, p->type, p->dst); + + XrmDestroyDatabase(db); } #if XRESOURCES_RELOAD_PATCH