- {
- int err;
- struct zlib_state *state =
- (struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));
-
- if (state == NULL)
- goto err;
-
- state->istream.zalloc = Z_NULL;
- state->istream.zfree = Z_NULL;
- state->istream.opaque = Z_NULL;
- state->istream.next_in = Z_NULL;
- state->istream.next_out = Z_NULL;
- state->istream.avail_in = 0;
- state->istream.avail_out = 0;
- err = inflateInit_(&state->istream,
- ZLIB_VERSION, sizeof(z_stream));
- if (err != Z_OK)
- goto err;
-
- state->ostream.zalloc = Z_NULL;
- state->ostream.zfree = Z_NULL;
- state->ostream.opaque = Z_NULL;
- state->ostream.next_in = Z_NULL;
- state->ostream.next_out = Z_NULL;
- state->ostream.avail_in = 0;
- state->ostream.avail_out = 0;
- err = deflateInit_(&state->ostream,Z_DEFAULT_COMPRESSION,
- ZLIB_VERSION, sizeof(z_stream));
- if (err != Z_OK)
- goto err;
-
- CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
- if (zlib_stateful_ex_idx == -1)
- {
- CRYPTO_w_lock(CRYPTO_LOCK_COMP);
- if (zlib_stateful_ex_idx == -1)
- zlib_stateful_ex_idx =
- CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
- 0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
- CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
- if (zlib_stateful_ex_idx == -1)
- goto err;
- }
- CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state);
- return 1;
+{
+ int err;
+ struct zlib_state *state = OPENSSL_zalloc(sizeof(*state));
+
+ if (state == NULL)
+ goto err;
+
+ state->istream.zalloc = zlib_zalloc;
+ state->istream.zfree = zlib_zfree;
+ state->istream.opaque = Z_NULL;
+ state->istream.next_in = Z_NULL;
+ state->istream.next_out = Z_NULL;
+ err = inflateInit_(&state->istream, ZLIB_VERSION, sizeof(z_stream));
+ if (err != Z_OK)
+ goto err;
+
+ state->ostream.zalloc = zlib_zalloc;
+ state->ostream.zfree = zlib_zfree;
+ state->ostream.opaque = Z_NULL;
+ state->ostream.next_in = Z_NULL;
+ state->ostream.next_out = Z_NULL;
+ err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
+ ZLIB_VERSION, sizeof(z_stream));
+ if (err != Z_OK)
+ goto err;
+
+ ctx->data = state;
+ return 1;