From 5ae641004ae86096b1f5edbb28cb65aa468fd4a6 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 14 Nov 2016 15:05:20 +1100 Subject: [PATCH 1/2] src/socket.lua: Remove dead code in socket:checktls() The inner code previously redeclared the same locals, shadowing the upvalues. This commit takes out the redundant code rather than removing the shadowing declaration as I'd like to support installing luaossl while a long-running cqueues program is running and have it automatically picked up. --- src/socket.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/socket.lua b/src/socket.lua index 12cfc86..07cd9cd 100644 --- a/src/socket.lua +++ b/src/socket.lua @@ -312,19 +312,10 @@ end) -- -- Smarter socket:checktls -- -local havessl, whynossl - local _checktls; _checktls = socket.interpose("checktls", function(self) + local havessl, whynossl = pcall(require, "openssl.ssl") if not havessl then - if havessl == false then - return nil, whynossl - end - - local havessl, whynossl = pcall(require, "openssl.ssl") - - if not havessl then - return nil, whynossl - end + return nil, whynossl end return _checktls(self) From adcfcb4b9ae011e281d208438f462bbf94f042ba Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 14 Nov 2016 16:44:09 +1100 Subject: [PATCH 2/2] src/lib/socket.c: free() pushback data once read --- src/lib/socket.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/socket.c b/src/lib/socket.c index 6424d0c..12a6b1d 100644 --- a/src/lib/socket.c +++ b/src/lib/socket.c @@ -2381,6 +2381,13 @@ static int bio_read(BIO *bio, char *dst, int lim) { memcpy(dst, so->bio.ahead.p, count); so->bio.ahead.p += count; + if (so->bio.ahead.p == so->bio.ahead.pe) { + free(so->bio.ahead.data); + so->bio.ahead.data = NULL; + so->bio.ahead.p = NULL; + so->bio.ahead.pe = NULL; + } + return count; }