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:
parent
490d2440da
commit
b8056cbf24
1 changed files with 7 additions and 1 deletions
|
|
@ -22,7 +22,8 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||||
|
|
||||||
switch (rtype) {
|
switch (rtype) {
|
||||||
case STRING:
|
case STRING:
|
||||||
*sdst = ret.addr;
|
/* Note: this leaks memory */
|
||||||
|
*sdst = strdup(ret.addr);
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
*idst = strtoul(ret.addr, NULL, 10);
|
*idst = strtoul(ret.addr, NULL, 10);
|
||||||
|
|
@ -47,8 +48,13 @@ config_init(Display *dpy)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
db = XrmGetStringDatabase(resm);
|
db = XrmGetStringDatabase(resm);
|
||||||
|
if (!db)
|
||||||
|
return;
|
||||||
|
|
||||||
for (p = resources; p < resources + LEN(resources); p++)
|
for (p = resources; p < resources + LEN(resources); p++)
|
||||||
resource_load(db, p->name, p->type, p->dst);
|
resource_load(db, p->name, p->type, p->dst);
|
||||||
|
|
||||||
|
XrmDestroyDatabase(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if XRESOURCES_RELOAD_PATCH
|
#if XRESOURCES_RELOAD_PATCH
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue