Commit Diff


commit - ba1a347dcaba055f824161007dfee60db3ea785b
commit + dfbbf7f6e1b22ccf9e5a45d77ee10995577fb4fc
blob - 27b7a30f0af26ef5d3c0e72c318673c38ab72150
blob + 4e7df12eee673974038aeefeb2daa4bd8a8a2e60
--- dmenu.c
+++ dmenu.c
@@ -550,11 +550,11 @@ static void
 readstdin(void)
 {
 	char *line = NULL;
-	size_t i, junk, itemsiz = 0;
+	size_t i, itemsiz = 0, linesiz = 0;
 	ssize_t len;
 
 	/* read each line from stdin and add it to the item list */
-	for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++) {
+	for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) {
 		if (i + 1 >= itemsiz) {
 			itemsiz += 256;
 			if (!(items = realloc(items, itemsiz * sizeof(*items))))
@@ -562,9 +562,10 @@ readstdin(void)
 		}
 		if (line[len - 1] == '\n')
 			line[len - 1] = '\0';
-		items[i].text = line;
+		if (!(items[i].text = strdup(line)))
+			die("strdup:");
+
 		items[i].out = 0;
-		line = NULL; /* next call of getline() allocates a new line */
 	}
 	free(line);
 	if (items)