Skip to content

Commit 4a55d15

Browse files
committed
Merge pull request #307
2 parents d914288 + 62a4175 commit 4a55d15

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

php_phongo.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

php_phongo_structs-5.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct {
5454
typedef struct {
5555
zend_object std;
5656
mongoc_client_t *client;
57+
char *pem_file;
5758
} php_phongo_manager_t;
5859

5960
typedef struct {

php_phongo_structs-7.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef struct {
5353

5454
typedef struct {
5555
mongoc_client_t *client;
56+
char *pem_file;
5657
zend_object std;
5758
} php_phongo_manager_t;
5859

src/MongoDB/Manager.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ static void php_phongo_manager_free_object(phongo_free_object_arg *object TSRMLS
389389
mongoc_client_destroy(intern->client);
390390
}
391391

392+
if (intern->pem_file) {
393+
efree(intern->pem_file);
394+
}
395+
392396
#if PHP_VERSION_ID < 70000
393397
efree(intern);
394398
#endif

0 commit comments

Comments
 (0)