[master] ad65850 Actually free the memory libvgz allocated to work in.

Poul-Henning Kamp phk at varnish-cache.org
Sat Mar 12 15:47:09 CET 2011


commit ad6585009cd59831cf85d2e264e811d408d34425
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Mar 12 14:45:27 2011 +0000

    Actually free the memory libvgz allocated to work in.
    
    No wonder gzip support leaked memory...
    
    Orginally this memory came from the the thread workspace so deallocation
    was automatic.  Not so when we switched to malloc...

diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 9b5180c..50f8c83 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -80,6 +80,7 @@ SVNID("$Id$")
 struct vgz {
 	unsigned		magic;
 #define VGZ_MAGIC		0x162df0cb
+	enum {VGZ_GZ,VGZ_UN}	dir;
 	struct sess		*sess;
 	const char		*id;
 	struct ws		*tmp;
@@ -162,6 +163,7 @@ VGZ_NewUngzip(struct sess *sp, const char *id)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	vg = vgz_alloc_vgz(sp, id);
+	vg->dir = VGZ_UN;
 	VSC_main->n_gunzip++;
 
 	/*
@@ -182,6 +184,7 @@ VGZ_NewGzip(struct sess *sp, const char *id)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	vg = vgz_alloc_vgz(sp, id);
+	vg->dir = VGZ_GZ;
 	VSC_main->n_gzip++;
 
 	/*
@@ -380,6 +383,10 @@ VGZ_Destroy(struct vgz **vgp)
 	    (intmax_t)vg->vz.stop_bit);
 	if (vg->tmp != NULL)
 		WS_Reset(vg->tmp, vg->tmp_snapshot);
+	if (vg->dir == VGZ_GZ)
+		AZ(deflateEnd(&vg->vz));
+	else
+		AZ(inflateEnd(&vg->vz));
 	FREE_OBJ(vg);
 }
 



More information about the varnish-commit mailing list