From a88524955f0fcff2d4bc6a3f84c6903c91b31c7d Mon Sep 17 00:00:00 2001 From: des Date: Fri, 19 Oct 2007 09:09:17 +0000 Subject: [PATCH] Move malloc() / free() out of the loop, and plug a leak. Ideally, we shouldn't need to malloc() / free() at all, but I don't have time to figure out how to avoid it right now. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2126 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_fetch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 318eeb03..1cab4d9a 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -298,18 +298,19 @@ Fetch(struct sess *sp) if (http_GetHdr(sp->http, H_Content_Length, &ptr)) { content_length = strtoul(ptr, &endp, 10); /* XXX should check result of conversion */ + p = malloc(content_length); while (content_length) { - p = malloc(content_length); read = HTC_Read(sp->htc, p, content_length); WRK_Write(w, p, read); if (WRK_Flush(w)) { VBE_UpdateHealth(sp, vc, -1); VBE_ClosedFd(sp->wrk, vc); + free(p); return (__LINE__); } content_length -= read; - free(p); } + free(p); } if (WRK_Flush(w)) { -- 2.39.5