@@ -1864,7 +1864,7 @@ static bool php_phongo_apply_wc_options_to_client(mongoc_client_t *client, bson_
18641864 return true;
18651865} /* }}} */
18661866
1867- static mongoc_client_t * php_phongo_make_mongo_client (const mongoc_uri_t * uri , zval * driverOptions TSRMLS_DC ) /* {{{ */
1867+ static mongoc_client_t * php_phongo_make_mongo_client (php_phongo_manager_t * manager , const mongoc_uri_t * uri , zval * driverOptions TSRMLS_DC ) /* {{{ */
18681868{
18691869#if PHP_VERSION_ID >= 70000
18701870 zval * tmp ;
@@ -1948,21 +1948,23 @@ static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, zv
19481948
19491949#if PHP_VERSION_ID >= 70000
19501950 if ((pem = php_stream_context_get_option (ctx , "ssl" , "local_cert" )) != NULL ) {
1951+ zend_string * s = zval_get_string (pem );
19511952#else
19521953 if (SUCCESS == php_stream_context_get_option (ctx , "ssl" , "local_cert" , & pem )) {
1954+ convert_to_string_ex (pem );
19531955#endif
1954- char filename [MAXPATHLEN ];
1956+ /* mongoc_client_set_ssl_opts() copies mongoc_ssl_opt_t shallowly;
1957+ * its strings must be kept valid for the life of mongoc_client_t */
1958+ manager -> pem_file = ecalloc (1 , MAXPATHLEN );
19551959
19561960#if PHP_VERSION_ID >= 70000
1957- zend_string * s = zval_get_string (pem );
1958- if (VCWD_REALPATH (ZSTR_VAL (s ), filename )) {
1961+ if (VCWD_REALPATH (ZSTR_VAL (s ), manager -> pem_file )) {
19591962#else
1960- convert_to_string_ex (pem );
1961- if (VCWD_REALPATH (Z_STRVAL_PP (pem ), filename )) {
1963+ if (VCWD_REALPATH (Z_STRVAL_PP (pem ), manager -> pem_file )) {
19621964#endif
1963- mongoc_ssl_opt_t ssl_options ;
1965+ mongoc_ssl_opt_t ssl_options = { 0 } ;
19641966
1965- ssl_options .pem_file = filename ;
1967+ ssl_options .pem_file = manager -> pem_file ;
19661968 mongoc_client_set_ssl_opts (client , & ssl_options );
19671969 }
19681970#if PHP_VERSION_ID >= 70000
@@ -1985,7 +1987,7 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
19851987 return false;
19861988 }
19871989
1988- manager -> client = php_phongo_make_mongo_client (uri , driverOptions TSRMLS_CC );
1990+ manager -> client = php_phongo_make_mongo_client (manager , uri , driverOptions TSRMLS_CC );
19891991 mongoc_uri_destroy (uri );
19901992
19911993 if (!manager -> client ) {
0 commit comments