libressl doesn't yet have sk_new_reserve.
correctly check for sk_X509_push failure.

Index: ext/openssl/openssl.c
--- ext/openssl/openssl.c.orig
+++ ext/openssl/openssl.c
@@ -2304,7 +2304,7 @@ static STACK_OF(X509) *php_openssl_load_all_certs_from
 		goto end;
 	}
 
-	if(!(stack = sk_X509_new_reserve(NULL, sk_X509_INFO_num(sk)))) {
+	if(!(stack = sk_X509_new_null())) {
 		php_openssl_store_errors();
 		goto end;
 	}
@@ -2313,7 +2313,11 @@ static STACK_OF(X509) *php_openssl_load_all_certs_from
 	while (sk_X509_INFO_num(sk)) {
 		xi=sk_X509_INFO_shift(sk);
 		if (xi->x509 != NULL) {
-			sk_X509_push(stack,xi->x509);
+			if(sk_X509_push(stack,xi->x509) == 0) {
+				php_error_docref(NULL, E_ERROR, "Memory allocation failure");
+				sk_X509_pop_free(stack,X509_free);
+				goto end;
+			}
 			xi->x509=NULL;
 		}
 		X509_INFO_free(xi);
