r2130 - trunk/varnish-cache/bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Fri Oct 19 11:47:53 CEST 2007


Author: des
Date: 2007-10-19 11:47:53 +0200 (Fri, 19 Oct 2007)
New Revision: 2130

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
Log:
Use an 8 kB stack buffer instead of a heap buffer.


Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-10-19 09:46:58 UTC (rev 2129)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-10-19 09:47:53 UTC (rev 2130)
@@ -260,10 +260,8 @@
 	struct bereq *bereq;
 	int mklen, is_head;
 	struct http_conn htc[1];
-	unsigned long content_length;
-	int i, read;
+	int i;
 	char *ptr, *endp;
-	char *p = NULL;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -296,21 +294,26 @@
 	 * pipelined bytes to the backend as well
 	 */
 	if (http_GetHdr(sp->http, H_Content_Length, &ptr)) {
+		unsigned long content_length;
+		char buf[8192];
+		int read;
+
 		content_length = strtoul(ptr, &endp, 10);
 		/* XXX should check result of conversion */
-		p = malloc(content_length);
 		while (content_length) {
-			read = HTC_Read(sp->htc, p, content_length);
-			WRK_Write(w, p, read);
+			if (content_length > sizeof buf)
+				read = sizeof buf;
+			else
+				read = content_length;
+			read = HTC_Read(sp->htc, buf, read);
+			WRK_Write(w, buf, read);
 			if (WRK_Flush(w)) {
 				VBE_UpdateHealth(sp, vc, -1);
 				VBE_ClosedFd(sp->wrk, vc);
-				free(p);
 				return (__LINE__);
 			}
 			content_length -= read;
 		}
-		free(p);
 	}
 
 	if (WRK_Flush(w)) {




More information about the varnish-commit mailing list