io.ports: More correct memory handling. There are still leaks in the tests...

db4
Doug Coleman 2012-08-25 19:44:22 -07:00
parent 3143222223
commit 30673f65cf
3 changed files with 58 additions and 36 deletions

View File

@ -202,7 +202,10 @@ M: output-port dispose*
] with-destructors ; ] with-destructors ;
M: buffered-port dispose* M: buffered-port dispose*
[ call-next-method ] [ buffer>> dispose ] bi ; [
[ buffer>> &dispose drop ]
[ call-next-method ] bi
] with-destructors ;
M: port cancel-operation handle>> cancel-operation ; M: port cancel-operation handle>> cancel-operation ;

View File

@ -133,10 +133,12 @@ M: openssl <secure-context> ( config -- context )
] with-destructors ; ] with-destructors ;
M: openssl-context dispose* M: openssl-context dispose*
[ aliens>> [ free ] each ] [
[ sessions>> values [ SSL_SESSION_free ] each ] [ aliens>> [ &free drop ] each ]
[ handle>> SSL_CTX_free ] [ sessions>> values [ SSL_SESSION_free ] each ]
tri ; [ handle>> SSL_CTX_free ]
tri
] with-destructors ;
TUPLE: ssl-handle < disposable file handle connected ; TUPLE: ssl-handle < disposable file handle connected ;
@ -150,13 +152,19 @@ SYMBOL: default-secure-context
] unless* ; ] unless* ;
: <ssl-handle> ( fd -- ssl ) : <ssl-handle> ( fd -- ssl )
ssl-handle new-disposable [
current-secure-context handle>> SSL_new ssl-handle new-disposable |dispose
dup ssl-error >>handle current-secure-context handle>> SSL_new
swap >>file ; dup ssl-error >>handle
swap >>file
] with-destructors ;
M: ssl-handle dispose* M: ssl-handle dispose*
[ handle>> SSL_free ] [ file>> dispose ] bi ; [
! Free file>> after SSL_free
[ file>> &dispose drop ]
[ handle>> SSL_free ] bi
] with-destructors ;
: check-verify-result ( ssl-handle -- ) : check-verify-result ( ssl-handle -- )
SSL_get_verify_result dup X509_V_OK = SSL_get_verify_result dup X509_V_OK =

View File

@ -65,10 +65,11 @@ io.sockets.secure.debug ;
[ ] [ [ ] [
[ [
"127.0.0.1" 0 <inet4> ascii <server> [ [
dup addr>> port>> "port" get fulfill "127.0.0.1" 0 <inet4> ascii <server> &dispose
accept drop 1 minutes sleep dispose dup addr>> port>> "port" get fulfill
] with-disposal accept drop &dispose 1 minutes sleep
] with-destructors
] "Silly server" spawn drop ] "Silly server" spawn drop
] unit-test ] unit-test
@ -83,18 +84,22 @@ io.sockets.secure.debug ;
[ ] [ [ ] [
[ [
"127.0.0.1" "port" get ?promise [
<inet4> ascii <client> drop 1 minutes sleep dispose "127.0.0.1" "port" get ?promise
<inet4> ascii <client> drop &dispose 1 minutes sleep
] with-destructors
] "Silly client" spawn drop ] "Silly client" spawn drop
] unit-test ] unit-test
[ [
1 seconds secure-socket-timeout [ 1 seconds secure-socket-timeout [
[ [
"127.0.0.1" 0 <inet4> <secure> ascii <server> [ [
dup addr>> addrspec>> port>> "port" get fulfill "127.0.0.1" 0 <inet4> <secure> ascii <server> [
accept drop dup stream-read1 drop dispose dup addr>> addrspec>> port>> "port" get fulfill
] with-disposal accept drop &dispose dup stream-read1 drop
] with-disposal
] with-destructors
] with-test-context ] with-test-context
] with-variable ] with-variable
] [ io-timeout? ] must-fail-with ] [ io-timeout? ] must-fail-with
@ -108,11 +113,13 @@ io.sockets.secure.debug ;
[ ] [ [ ] [
[ [
[ [
"127.0.0.1" 0 <inet4> <secure> ascii <server> [ [
dup addr>> addrspec>> port>> "port" get fulfill "127.0.0.1" 0 <inet4> <secure> ascii <server> [
accept drop 1 minutes sleep dispose dup addr>> addrspec>> port>> "port" get fulfill
] with-disposal accept drop &dispose 1 minutes sleep
] with-test-context ] with-disposal
] with-test-context
] with-destructors
] "Silly server" spawn drop ] "Silly server" spawn drop
] unit-test ] unit-test
@ -131,20 +138,24 @@ io.sockets.secure.debug ;
[ ] [ [ ] [
[ [
[ [
"127.0.0.1" "port" get ?promise [
<inet4> <secure> ascii <client> drop 1 minutes sleep dispose "127.0.0.1" "port" get ?promise
] with-test-context <inet4> <secure> ascii <client> drop &dispose 1 minutes sleep
] with-test-context
] with-destructors
] "Silly client" spawn drop ] "Silly client" spawn drop
] unit-test ] unit-test
[ [
1 seconds secure-socket-timeout [ [
[ 1 seconds secure-socket-timeout [
"127.0.0.1" 0 <inet4> <secure> ascii <server> [ [
dup addr>> addrspec>> port>> "port" get fulfill "127.0.0.1" 0 <inet4> <secure> ascii <server> [
accept drop dispose dup addr>> addrspec>> port>> "port" get fulfill
] with-disposal accept drop &dispose
] with-test-context ] with-disposal
] with-variable ] with-test-context
] with-variable
] with-destructors
] [ io-timeout? ] must-fail-with ] [ io-timeout? ] must-fail-with
] drop ] drop