From 4947c1852f30e4443bd2fb5a8e433165c9c6f108 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 12 Mar 2014 14:29:15 -0400 Subject: [PATCH] Heap-allocate zlib data structure in regress_zlib tests --- test/regress_zlib.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/regress_zlib.c b/test/regress_zlib.c index 9339397c..84066769 100644 --- a/test/regress_zlib.c +++ b/test/regress_zlib.c @@ -56,6 +56,7 @@ #include "event2/bufferevent.h" #include "regress.h" +#include "mm-internal.h" /* zlib 1.2.4 and 1.2.5 do some "clever" things with macros. Instead of saying "(defined(FOO) ? FOO : 0)" they like to say "FOO-0", on the theory @@ -95,6 +96,7 @@ zlib_deflate_free(void *ctx) z_streamp p = ctx; assert(deflateEnd(p) == Z_OK); + mm_free(p); } static void @@ -103,6 +105,7 @@ zlib_inflate_free(void *ctx) z_streamp p = ctx; assert(inflateEnd(p) == Z_OK); + mm_free(p); } static int @@ -275,7 +278,7 @@ test_bufferevent_zlib(void *arg) { struct bufferevent *bev1=NULL, *bev2=NULL; char buffer[8333]; - z_stream z_input, z_output; + z_stream *z_input, *z_output; int i, r; evutil_socket_t pair[2] = {-1, -1}; (void)arg; @@ -293,18 +296,18 @@ test_bufferevent_zlib(void *arg) bev1 = bufferevent_socket_new(NULL, pair[0], 0); bev2 = bufferevent_socket_new(NULL, pair[1], 0); - memset(&z_output, 0, sizeof(z_output)); - r = deflateInit(&z_output, Z_DEFAULT_COMPRESSION); + z_output = mm_calloc(sizeof(*z_output), 1); + r = deflateInit(z_output, Z_DEFAULT_COMPRESSION); tt_int_op(r, ==, Z_OK); - memset(&z_input, 0, sizeof(z_input)); - r = inflateInit(&z_input); + z_input = mm_calloc(sizeof(*z_input), 1); + r = inflateInit(z_input); tt_int_op(r, ==, Z_OK); /* initialize filters */ bev1 = bufferevent_filter_new(bev1, NULL, zlib_output_filter, - BEV_OPT_CLOSE_ON_FREE, zlib_deflate_free, &z_output); + BEV_OPT_CLOSE_ON_FREE, zlib_deflate_free, z_output); bev2 = bufferevent_filter_new(bev2, zlib_input_filter, - NULL, BEV_OPT_CLOSE_ON_FREE, zlib_inflate_free, &z_input); + NULL, BEV_OPT_CLOSE_ON_FREE, zlib_inflate_free, z_input); bufferevent_setcb(bev1, readcb, writecb, errorcb, NULL); bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL); -- 2.40.0