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.
This commit is contained in:
Bakkeby 2026-01-29 21:28:16 +01:00
parent 490d2440da
commit b8056cbf24

View file

@ -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