From: phk Date: Sun, 15 Jul 2007 10:22:39 +0000 (+0000) Subject: Plug a memory-leak in the VCL compiler. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e0ea29993a97fc9d45ce2dbc26e5606dcc956dc;p=varnish Plug a memory-leak in the VCL compiler. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1700 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index f675afe2..07eca8e2 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -95,18 +95,26 @@ static const char *vcc_default_vcl_b, *vcc_default_vcl_e; /*--------------------------------------------------------------------*/ -void * -TlAlloc(struct tokenlist *tl, unsigned len) +void +TlFree(struct tokenlist *tl, void *p) { struct membit *mb; - void *p; - p = calloc(len, 1); - assert(p != NULL); mb = calloc(sizeof *mb, 1); assert(mb != NULL); mb->ptr = p; TAILQ_INSERT_TAIL(&tl->membits, mb, list); +} + + +void * +TlAlloc(struct tokenlist *tl, unsigned len) +{ + void *p; + + p = calloc(len, 1); + assert(p != NULL); + TlFree(tl, p); return (p); } diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index dd0da275..df4441e8 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -153,6 +153,7 @@ void Fi(const struct tokenlist *tl, int indent, const char *fmt, ...); void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...); void EncToken(struct vsb *sb, const struct token *t); int IsMethod(const struct token *t); +void TlFree(struct tokenlist *tl, void *p); void *TlAlloc(struct tokenlist *tl, unsigned len); /* vcc_obj.c */ diff --git a/varnish-cache/lib/libvcl/vcc_var.c b/varnish-cache/lib/libvcl/vcc_var.c index 33cf04e8..110f0898 100644 --- a/varnish-cache/lib/libvcl/vcc_var.c +++ b/varnish-cache/lib/libvcl/vcc_var.c @@ -64,10 +64,12 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); + TlFree(tl, p); v->rname = p; asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); + TlFree(tl, p); v->lname = p; return (v); }