about summary refs log tree commit diff
diff options
context:
space:
mode:
authortim <tim>2020-03-16 17:50:44 +0000
committertim <tim>2020-03-16 17:50:44 +0000
commit3b9b98c024dc0100af3a0700d8057b2ea96a6714 (patch)
tree088f0bdc6b83ed0600914b5fb4be388e8801796e
parentb9213d0a02de1254358a878cf14ee53f4fb4df0d (diff)
downloadcwm-3b9b98c024dc0100af3a0700d8057b2ea96a6714.tar.gz
cwm-3b9b98c024dc0100af3a0700d8057b2ea96a6714.tar.xz
cwm-3b9b98c024dc0100af3a0700d8057b2ea96a6714.zip
Recommit 1.259, but now with TAILQ_FOREACH_SAFE.
From and OK okan@

Original commit message:

Plug two memory leaks. Also get rid of a variable that is no longer
necessary.

OK okan@
-rw-r--r--client.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/client.c b/client.c
index 653c0d4..21c51bc 100644
--- a/client.c
+++ b/client.c
@@ -667,22 +667,24 @@ client_close(struct client_ctx *cc)
 void
 client_set_name(struct client_ctx *cc)
 {
-	struct winname	*wn;
-	char		*newname;
+	struct winname	*wn, *wnnxt;
 	int		 i = 0;
 
-	if (!xu_get_strprop(cc->win, ewmh[_NET_WM_NAME], &newname))
-		if (!xu_get_strprop(cc->win, XA_WM_NAME, &newname))
-			newname = xstrdup("");
+	free(cc->name);
+	if (!xu_get_strprop(cc->win, ewmh[_NET_WM_NAME], &cc->name))
+		if (!xu_get_strprop(cc->win, XA_WM_NAME, &cc->name))
+			cc->name = xstrdup("");
 
-	TAILQ_FOREACH(wn, &cc->nameq, entry) {
-		if (strcmp(wn->name, newname) == 0)
+	TAILQ_FOREACH_SAFE(wn, &cc->nameq, entry, wnnxt) {
+		if (strcmp(wn->name, cc->name) == 0) {
 			TAILQ_REMOVE(&cc->nameq, wn, entry);
+			free(wn->name);
+			free(wn);
+		}
 		i++;
 	}
-	cc->name = newname;
 	wn = xmalloc(sizeof(*wn));
-	wn->name = xstrdup(newname);
+	wn->name = xstrdup(cc->name);
 	TAILQ_INSERT_TAIL(&cc->nameq, wn, entry);
 
 	/* Garbage collection. */