Fix the bad-data PKCS7 case.  Also fix a memory BIO issue on PyPy by copying the string input data before giving it to the BIO, and also explicitly keeping the data alive as long as the BIO stays alive.  This may still not be correct (on CPython or PyPy) because BIO_free ostensibly frees the data passed to it.
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 0660703..15e3b6a 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -25,11 +25,18 @@
 def _new_mem_buf(buffer=None):
     if buffer is None:
         bio = _api.BIO_new(_api.BIO_s_mem())
+        free = _api.BIO_free
     else:
-        bio = _api.BIO_new_mem_buf(buffer, len(buffer))
+        data = _api.ffi.new("char[]", buffer)
+        bio = _api.BIO_new_mem_buf(data, len(buffer))
+        # Keep the memory alive as long as the bio is alive!
+        def free(bio, ref=data):
+            return _api.BIO_free(bio)
+
     if bio == _api.NULL:
         1/0
-    bio = _api.ffi.gc(bio, _api.BIO_free)
+
+    bio = _api.ffi.gc(bio, free)
     return bio
 
 
@@ -1959,7 +1966,7 @@
         raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
 
     if pkcs7 == _api.NULL:
-        1/0
+        _raise_current_error()
 
     pypkcs7 = PKCS7.__new__(PKCS7)
     pypkcs7._pkcs7 = _api.ffi.gc(pkcs7, _api.PKCS7_free)