Avoid quadratic behavior in reading SSL data
authorAlexey Shchepin <alexey@process-one.net>
Mon, 20 Feb 2012 15:41:56 +0000 (17:41 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Fri, 6 Apr 2012 09:47:53 +0000 (11:47 +0200)
src/tls/tls_drv.c

index dabe1491136ccb0dd4292b1f793d85158531eff9..e680cde65039a854b5166285119843ea456a2a7e 100644 (file)
@@ -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)