that the limit applies both to incoming and outgoing connections, so one
connection which is deciphered then ciphered accounts for 2 SSL connections.
+maxzlibmem <number>
+ Sets the maximum amount of RAM in megabytes per process usable by the zlib.
+ When the maximum amount is reached, future sessions will not compress as long
+ as RAM is unavailable. When sets to 0, there is no limit.
+ The default value is 0.
+
noepoll
Disables the use of the "epoll" event polling system on Linux. It is
equivalent to the command-line argument "-de". The next polling system
}
global.maxpipes = atol(args[1]);
}
+ else if (!strcmp(args[0], "maxzlibmem")) {
+ if (*(args[1]) == 0) {
+ Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+ }
+ global.maxzlibmem = atol(args[1]);
+ }
else if (!strcmp(args[0], "ulimit-n")) {
if (global.rlimit_nofile != 0) {
Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
static struct pool_head *zlib_pool_head = NULL;
static struct pool_head *zlib_pool_pending_buf = NULL;
+static long long zlib_memory_available = -1;
+
+
#endif
static char round = 0; /* order in deflateInit2 */
void *buf = NULL;
+ if (global.maxzlibmem > 0 && zlib_memory_available < items * size){
+ buf = NULL;
+ goto end;
+ }
+
switch (round) {
case 0:
if (zlib_pool_deflate_state == NULL)
ctx->zlib_pending_buf = buf = pool_alloc2(zlib_pool_pending_buf);
break;
}
+ if (buf != NULL && global.maxzlibmem > 0)
+ zlib_memory_available -= items * size;
+
+end:
round = (round + 1) % 5; /* there are 5 zalloc call in deflateInit2 */
return buf;
static void free_zlib(void *opaque, void *ptr)
{
struct comp_ctx *ctx = opaque;
+ struct pool_head *pool;
if (ptr == ctx->zlib_window)
- pool_free2(zlib_pool_window, ptr);
+ pool = zlib_pool_window;
else if (ptr == ctx->zlib_deflate_state)
- pool_free2(zlib_pool_deflate_state, ptr);
+ pool = zlib_pool_deflate_state;
else if (ptr == ctx->zlib_prev)
- pool_free2(zlib_pool_prev, ptr);
+ pool = zlib_pool_prev;
else if (ptr == ctx->zlib_head)
- pool_free2(zlib_pool_head, ptr);
+ pool = zlib_pool_head;
else if (ptr == ctx->zlib_pending_buf)
- pool_free2(zlib_pool_pending_buf, ptr);
+ pool = zlib_pool_pending_buf;
+ pool_free2(pool, ptr);
+ if (global.maxzlibmem > 0)
+ zlib_memory_available += pool->size;
}
{
z_stream *strm = &comp_ctx->strm;
+ if (global.maxzlibmem > 0 && zlib_memory_available < 0)
+ zlib_memory_available = global.maxzlibmem * 1024 * 1024; /* Megabytes to bytes */
+
strm->zalloc = alloc_zlib;
strm->zfree = free_zlib;
strm->opaque = comp_ctx;
{
z_stream *strm = &comp_ctx->strm;
- if (deflateEnd(strm) == Z_OK)
- return 0;
+ if (deflateEnd(strm) != Z_OK)
+ return -1;
- return -1;
+ return 0;
}
#endif /* USE_ZLIB */