]> gitweb.factorcode.org Git - factor.git/commitdiff
io.ports: More correct memory handling. There are still leaks in the tests...
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Aug 2012 02:44:22 +0000 (19:44 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Aug 2012 02:44:22 +0000 (19:44 -0700)
basis/io/ports/ports.factor
basis/io/sockets/secure/openssl/openssl.factor
basis/io/sockets/secure/unix/unix-tests.factor

index 6b60ee2133468e53cba0a140727972b47150e858..f4d01472809d661881f7136d42ddcef9bc01cc51 100644 (file)
@@ -202,7 +202,10 @@ M: output-port dispose*
     ] with-destructors ;
 
 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 ;
 
index ca7ba0cd497671f4e234ffc5ecb173e0e28addb4..49b9820574c284c4f7cdfdaeb893a655608e8a1b 100644 (file)
@@ -133,10 +133,12 @@ M: openssl <secure-context> ( config -- context )
     ] with-destructors ;
 
 M: openssl-context dispose*
-    [ aliens>> [ free ] each ]
-    [ sessions>> values [ SSL_SESSION_free ] each ]
-    [ handle>> SSL_CTX_free ]
-    tri ;
+    [
+        [ aliens>> [ &free drop ] each ]
+        [ sessions>> values [ SSL_SESSION_free ] each ]
+        [ handle>> SSL_CTX_free ]
+        tri
+    ] with-destructors ;
 
 TUPLE: ssl-handle < disposable file handle connected ;
 
@@ -150,13 +152,19 @@ SYMBOL: default-secure-context
     ] unless* ;
 
 : <ssl-handle> ( fd -- ssl )
-    ssl-handle new-disposable
-    current-secure-context handle>> SSL_new
-    dup ssl-error >>handle
-    swap >>file ;
+    [
+        ssl-handle new-disposable |dispose
+        current-secure-context handle>> SSL_new
+        dup ssl-error >>handle
+        swap >>file
+    ] with-destructors ;
 
 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 -- )
     SSL_get_verify_result dup X509_V_OK =
index d8619d9bac76c217364255ba62a57782a430a958..e6759109b9bf833906a1e777729a63297059ca1d 100644 (file)
@@ -65,10 +65,11 @@ io.sockets.secure.debug ;
 
 [ ] [
     [
-        "127.0.0.1" 0 <inet4> ascii <server> [
-            dup addr>> port>> "port" get fulfill
-            accept drop 1 minutes sleep dispose
-        ] with-disposal
+        [
+            "127.0.0.1" 0 <inet4> ascii <server> &dispose 
+                dup addr>> port>> "port" get fulfill
+                accept drop &dispose 1 minutes sleep
+        ] with-destructors
     ] "Silly server" spawn drop
 ] 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
 ] unit-test
 
 [
     1 seconds secure-socket-timeout [
         [
-            "127.0.0.1" 0 <inet4> <secure> ascii <server> [
-                dup addr>> addrspec>> port>> "port" get fulfill
-                accept drop dup stream-read1 drop dispose
-            ] with-disposal
+            [
+                "127.0.0.1" 0 <inet4> <secure> ascii <server> [
+                    dup addr>> addrspec>> port>> "port" get fulfill
+                    accept drop &dispose dup stream-read1 drop
+                ] with-disposal
+            ] with-destructors
         ] with-test-context
     ] with-variable
 ] [ 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
-                    accept drop 1 minutes sleep dispose
-                ] with-disposal
-            ] with-test-context
+                [
+                    "127.0.0.1" 0 <inet4> <secure> ascii <server> [
+                        dup addr>> addrspec>> port>> "port" get fulfill
+                        accept drop &dispose 1 minutes sleep
+                    ] with-disposal
+                ] with-test-context
+            ] with-destructors
         ] "Silly server" spawn drop
     ] 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
-            ] with-test-context
+                [
+                    "127.0.0.1" "port" get ?promise
+                    <inet4> <secure> ascii <client> drop &dispose 1 minutes sleep
+                ] with-test-context
+            ] with-destructors
         ] "Silly client" spawn drop
     ] unit-test
     
     [
-        1 seconds secure-socket-timeout [
-            [
-                "127.0.0.1" 0 <inet4> <secure> ascii <server> [
-                    dup addr>> addrspec>> port>> "port" get fulfill
-                    accept drop dispose
-                ] with-disposal
-            ] with-test-context
-        ] with-variable
+        [
+            1 seconds secure-socket-timeout [
+                [
+                    "127.0.0.1" 0 <inet4> <secure> ascii <server> [
+                        dup addr>> addrspec>> port>> "port" get fulfill
+                        accept drop &dispose
+                    ] with-disposal
+                ] with-test-context
+            ] with-variable
+        ] with-destructors
     ] [ io-timeout? ] must-fail-with
 ] drop