From: Hiltjo Posthuma Date: Sun, 4 Nov 2018 13:35:07 +0000 (+0100) Subject: fix memory leak in xloadcols() X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=d7bf023b2f2d41cb6983bb3ce2c6d1bf049150b3;p=st.git fix memory leak in xloadcols() reported by Avi Halachmi (:avih)" patch slightly changed by me. --- diff --git a/x.c b/x.c index 00cb6b1..0422421 100644 --- a/x.c +++ b/x.c @@ -733,12 +733,12 @@ xloadcols(void) static int loaded; Color *cp; - dc.collen = MAX(LEN(colorname), 256); - dc.col = xmalloc(dc.collen * sizeof(Color)); - if (loaded) { for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); + } else { + dc.collen = MAX(LEN(colorname), 256); + dc.col = xmalloc(dc.collen * sizeof(Color)); } for (i = 0; i < dc.collen; i++)