From 4637e2c66b1e23f9aade78a9831b58fe53ee9676 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Mon, 20 Feb 2012 17:41:56 +0200 Subject: [PATCH] Avoid quadratic behavior in reading SSL data --- src/tls/tls_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tls/tls_drv.c b/src/tls/tls_drv.c index dabe14911..e680cde65 100644 --- a/src/tls/tls_drv.c +++ b/src/tls/tls_drv.c @@ -442,8 +442,10 @@ static ErlDrvSSizeT tls_drv_control(ErlDrvData handle, { //printf("%d bytes of decrypted data read from state machine\r\n",res); rlen += res; - size += BUF_SIZE; - b = driver_realloc_binary(b, size); + if (size - rlen < BUF_SIZE) { + size *= 2; + b = driver_realloc_binary(b, size); + } } if (res < 0)