diff -r c12572045630 dmenu.c
--- a/dmenu.c	Thu Apr 01 21:40:11 2010 +0100
+++ b/dmenu.c	Fri Apr 02 01:01:36 2010 +0000
@@ -616,16 +616,21 @@
 void
 readstdin(void) {
 	char *p, buf[sizeof text];
-	unsigned int len = 0, max = 0;
+	unsigned int len = 0, blen = 0, max = 0;
 	Item *i, *new;
 
 	i = NULL;
+	p = NULL;
 	while(fgets(buf, sizeof buf, stdin)) {
-		len = strlen(buf);
-		if(buf[len-1] == '\n')
-			buf[--len] = '\0';
-		if(!(p = strdup(buf)))
-			eprint("fatal: could not strdup() %u bytes\n", len);
+		blen = strlen(buf);
+		if(!(p = realloc(p, len + blen)))
+			eprint("fatal: could not realloc() %u bytes\n", len + blen);
+		memcpy(p + len, buf, blen);
+		len += blen;
+		if(p[len-1] == '\n')
+			p[--len] = '\0';
+		else if(!feof(stdin))
+			continue;
 		if(max < len) {
 			maxname = p;
 			max = len;
@@ -639,6 +644,8 @@
 		else 
 			i->next = new;
 		i = new;
+		p = NULL;
+		len = 0;
 	}
 }
 
