nsxivd9e60cb
Fix memory leak in win_res()
Fixes issue #372.
+13 −11
1 file changed
- M window.c +13 −11
| @@ -71,18 +71,14 @@ void win_alloc_color(const win_env_t *e, const char *name, XftColor *col) | |||
| 71 | 71 | } | |
| 72 | 72 | } | |
| 73 | 73 | ||
| 74 | − | const char* win_res(Display *dpy, const char *name, const char *def) | |
| 74 | + | const char* win_res(XrmDatabase db, const char *name, const char *def) | |
| 75 | 75 | { | |
| 76 | 76 | char *type; | |
| 77 | 77 | XrmValue ret; | |
| 78 | − | XrmDatabase db; | |
| 79 | − | char *res_man; | |
| 80 | − | ||
| 81 | − | XrmInitialize(); | |
| 82 | 78 | ||
| 83 | − | if ((res_man = XResourceManagerString(dpy)) != NULL && | |
| 84 | − | (db = XrmGetStringDatabase(res_man)) != NULL && | |
| 85 | − | XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String")) | |
| 79 | + | if (db != None && | |
| 80 | + | XrmGetResource(db, name, name, &type, &ret) && | |
| 81 | + | STREQ(type, "String")) | |
| 86 | 82 | { | |
| 87 | 83 | return ret.addr; | |
| 88 | 84 | } else { | |
| @@ -97,6 +93,8 @@ void win_init(win_t *win) | |||
| 97 | 93 | { | |
| 98 | 94 | win_env_t *e; | |
| 99 | 95 | const char *bg, *fg, *f; | |
| 96 | + | char *res_man; | |
| 97 | + | XrmDatabase db; | |
| 100 | 98 | ||
| 101 | 99 | memset(win, 0, sizeof(win_t)); | |
| 102 | 100 | ||
| @@ -114,11 +112,15 @@ void win_init(win_t *win) | |||
| 114 | 112 | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) | |
| 115 | 113 | error(0, 0, "No locale support"); | |
| 116 | 114 | ||
| 117 | − | f = win_res(e->dpy, RES_CLASS ".font", "monospace-8"); | |
| 115 | + | XrmInitialize(); | |
| 116 | + | res_man = XResourceManagerString(e->dpy); | |
| 117 | + | db = res_man != NULL ? XrmGetStringDatabase(res_man) : None; | |
| 118 | + | ||
| 119 | + | f = win_res(db, RES_CLASS ".font", "monospace-8"); | |
| 118 | 120 | win_init_font(e, f); | |
| 119 | 121 | ||
| 120 | − | bg = win_res(e->dpy, RES_CLASS ".background", "white"); | |
| 121 | − | fg = win_res(e->dpy, RES_CLASS ".foreground", "black"); | |
| 122 | + | bg = win_res(db, RES_CLASS ".background", "white"); | |
| 123 | + | fg = win_res(db, RES_CLASS ".foreground", "black"); | |
| 122 | 124 | win_alloc_color(e, bg, &win->bg); | |
| 123 | 125 | win_alloc_color(e, fg, &win->fg); | |
| 124 | 126 | ||