]> err.no Git - varnish/commitdiff
Move malloc() / free() out of the loop, and plug a leak. Ideally, we
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 19 Oct 2007 09:09:17 +0000 (09:09 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 19 Oct 2007 09:09:17 +0000 (09:09 +0000)
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

index 318eeb03d3caf5f2301c7d0b0f625fa22d5c5a48..1cab4d9a7aaee3d98dc982e5f91ee24ed4be8a9b 100644 (file)
@@ -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)) {