Only free if it ain't NULL.
diff --git a/CHANGES b/CHANGES
index 3606450..b2e31d6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@
 
  Changes between 0.9.1c and 0.9.2
 
+  *) rsa_eay.c would attempt to free a NULL context.
+     [Arne Ansper <arne@ats.cyber.ee>]
+
   *) BIO_s_socket() had a broken should_retry() on Windoze.
      [Arne Ansper <arne@ats.cyber.ee>]
 
diff --git a/crypto/rsa/rsa_eay.c b/crypto/rsa/rsa_eay.c
index b405050..ec143e8 100644
--- a/crypto/rsa/rsa_eay.c
+++ b/crypto/rsa/rsa_eay.c
@@ -474,7 +474,8 @@
 err:
 	BN_clear_free(&m1);
 	BN_clear_free(&r1);
-	BN_CTX_free(ctx);
+	if(ctx)
+	    BN_CTX_free(ctx);
 	return(ret);
 	}
 
diff --git a/crypto/rsa/rsa_enc.c b/crypto/rsa/rsa_enc.c
index c4a4ad5..5f91239 100644
--- a/crypto/rsa/rsa_enc.c
+++ b/crypto/rsa/rsa_enc.c
@@ -531,7 +531,8 @@
 err:
 	if (m1 != NULL) BN_free(m1);
 	if (r1 != NULL) BN_free(r1);
-	BN_CTX_free(ctx);
+	if(ctx != NULL)
+	    BN_CTX_free(ctx);
 	return(ret);
 	}