make register_cipher_adapter private and fix cryptorref release
diff --git a/cryptography/hazmat/backends/commoncrypto/backend.py b/cryptography/hazmat/backends/commoncrypto/backend.py
index a9ffba4..cdce5f4 100644
--- a/cryptography/hazmat/backends/commoncrypto/backend.py
+++ b/cryptography/hazmat/backends/commoncrypto/backend.py
@@ -120,8 +120,8 @@
     def create_symmetric_decryption_ctx(self, cipher, mode):
         return _CipherContext(self, cipher, mode, _CipherContext._DECRYPT)
 
-    def register_cipher_adapter(self, cipher_cls, cipher_const, mode_cls,
-                                mode_const):
+    def _register_cipher_adapter(self, cipher_cls, cipher_const, mode_cls,
+                                 mode_const):
         if (cipher_cls, mode_cls) in self._cipher_registry:
             raise ValueError("Duplicate registration for: {0} {1}".format(
                 cipher_cls, mode_cls)
@@ -135,7 +135,7 @@
             (CFB, self._lib.kCCModeCFB), (OFB, self._lib.kCCModeOFB),
             (CTR, self._lib.kCCModeCTR)
         ]:
-            self.register_cipher_adapter(
+            self._register_cipher_adapter(
                 AES,
                 self._lib.kCCAlgorithmAES128,
                 mode_cls,
@@ -145,7 +145,7 @@
             (CBC, self._lib.kCCModeCBC), (CFB, self._lib.kCCModeCFB),
             (OFB, self._lib.kCCModeOFB),
         ]:
-            self.register_cipher_adapter(
+            self._register_cipher_adapter(
                 TripleDES,
                 self._lib.kCCAlgorithm3DES,
                 mode_cls,
@@ -155,13 +155,13 @@
             (CBC, self._lib.kCCModeCBC), (ECB, self._lib.kCCModeECB),
             (CFB, self._lib.kCCModeCFB), (OFB, self._lib.kCCModeOFB),
         ]:
-            self.register_cipher_adapter(
+            self._register_cipher_adapter(
                 Blowfish,
                 self._lib.kCCAlgorithmBlowfish,
                 mode_cls,
                 mode_const
             )
-        self.register_cipher_adapter(
+        self._register_cipher_adapter(
             ARC4,
             self._lib.kCCAlgorithmRC4,
             type(None),
@@ -189,8 +189,10 @@
     Called by the garbage collector and used to safely dereference and
     release the context.
     """
-    res = backend._lib.CCCryptorRelease(ctx[0])
-    backend._check_response(res)
+    if ctx[0] != backend._ffi.NULL:
+        res = backend._lib.CCCryptorRelease(ctx[0])
+        backend._check_response(res)
+        ctx[0] = backend._ffi.NULL
 
 
 @utils.register_interface(interfaces.CipherContext)
@@ -278,8 +280,7 @@
         res = self._backend._lib.CCCryptorFinal(
             self._ctx[0], buf, len(buf), outlen)
         self._backend._check_response(res)
-        # TODO: how do we release this here without causing a crash when
-        # the GC also releases it?
+        _release_cipher_ctx(self._ctx)
         return self._backend._ffi.buffer(buf)[:outlen[0]]
 
 
diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py
index 8022863..68ab6bc 100644
--- a/tests/hazmat/backends/test_commoncrypto.py
+++ b/tests/hazmat/backends/test_commoncrypto.py
@@ -28,7 +28,7 @@
     def test_register_duplicate_cipher_adapter(self):
         from cryptography.hazmat.backends.commoncrypto.backend import backend
         with pytest.raises(ValueError):
-            backend.register_cipher_adapter(
+            backend._register_cipher_adapter(
                 AES, backend._lib.kCCAlgorithmAES128,
                 CBC, backend._lib.kCCModeCBC
             )