mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Heap-allocate zlib data structure in regress_zlib tests
This commit is contained in:
parent
57abb35947
commit
4947c1852f
@ -56,6 +56,7 @@
|
|||||||
#include "event2/bufferevent.h"
|
#include "event2/bufferevent.h"
|
||||||
|
|
||||||
#include "regress.h"
|
#include "regress.h"
|
||||||
|
#include "mm-internal.h"
|
||||||
|
|
||||||
/* zlib 1.2.4 and 1.2.5 do some "clever" things with macros. Instead of
|
/* 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
|
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;
|
z_streamp p = ctx;
|
||||||
|
|
||||||
assert(deflateEnd(p) == Z_OK);
|
assert(deflateEnd(p) == Z_OK);
|
||||||
|
mm_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -103,6 +105,7 @@ zlib_inflate_free(void *ctx)
|
|||||||
z_streamp p = ctx;
|
z_streamp p = ctx;
|
||||||
|
|
||||||
assert(inflateEnd(p) == Z_OK);
|
assert(inflateEnd(p) == Z_OK);
|
||||||
|
mm_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -275,7 +278,7 @@ test_bufferevent_zlib(void *arg)
|
|||||||
{
|
{
|
||||||
struct bufferevent *bev1=NULL, *bev2=NULL;
|
struct bufferevent *bev1=NULL, *bev2=NULL;
|
||||||
char buffer[8333];
|
char buffer[8333];
|
||||||
z_stream z_input, z_output;
|
z_stream *z_input, *z_output;
|
||||||
int i, r;
|
int i, r;
|
||||||
evutil_socket_t pair[2] = {-1, -1};
|
evutil_socket_t pair[2] = {-1, -1};
|
||||||
(void)arg;
|
(void)arg;
|
||||||
@ -293,18 +296,18 @@ test_bufferevent_zlib(void *arg)
|
|||||||
bev1 = bufferevent_socket_new(NULL, pair[0], 0);
|
bev1 = bufferevent_socket_new(NULL, pair[0], 0);
|
||||||
bev2 = bufferevent_socket_new(NULL, pair[1], 0);
|
bev2 = bufferevent_socket_new(NULL, pair[1], 0);
|
||||||
|
|
||||||
memset(&z_output, 0, sizeof(z_output));
|
z_output = mm_calloc(sizeof(*z_output), 1);
|
||||||
r = deflateInit(&z_output, Z_DEFAULT_COMPRESSION);
|
r = deflateInit(z_output, Z_DEFAULT_COMPRESSION);
|
||||||
tt_int_op(r, ==, Z_OK);
|
tt_int_op(r, ==, Z_OK);
|
||||||
memset(&z_input, 0, sizeof(z_input));
|
z_input = mm_calloc(sizeof(*z_input), 1);
|
||||||
r = inflateInit(&z_input);
|
r = inflateInit(z_input);
|
||||||
tt_int_op(r, ==, Z_OK);
|
tt_int_op(r, ==, Z_OK);
|
||||||
|
|
||||||
/* initialize filters */
|
/* initialize filters */
|
||||||
bev1 = bufferevent_filter_new(bev1, NULL, zlib_output_filter,
|
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,
|
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(bev1, readcb, writecb, errorcb, NULL);
|
||||||
bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL);
|
bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user