Skip to content

Commit 2608dbb

Browse files
committed
Merge branch 'v1.1'
2 parents 71831a1 + 4a55d15 commit 2608dbb

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
@@ -1870,7 +1870,7 @@ static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t *uri, bson_t *option
18701870
return true;
18711871
} /* }}} */
18721872

1873-
static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, zval *driverOptions TSRMLS_DC) /* {{{ */
1873+
static mongoc_client_t *php_phongo_make_mongo_client(php_phongo_manager_t *manager, const mongoc_uri_t *uri, zval *driverOptions TSRMLS_DC) /* {{{ */
18741874
{
18751875
#if PHP_VERSION_ID >= 70000
18761876
zval *tmp;
@@ -1954,21 +1954,23 @@ static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, zv
19541954

19551955
#if PHP_VERSION_ID >= 70000
19561956
if ((pem = php_stream_context_get_option(ctx, "ssl", "local_cert")) != NULL) {
1957+
zend_string *s = zval_get_string(pem);
19571958
#else
19581959
if (SUCCESS == php_stream_context_get_option(ctx, "ssl", "local_cert", &pem)) {
1960+
convert_to_string_ex(pem);
19591961
#endif
1960-
char filename[MAXPATHLEN];
1962+
/* mongoc_client_set_ssl_opts() copies mongoc_ssl_opt_t shallowly;
1963+
* its strings must be kept valid for the life of mongoc_client_t */
1964+
manager->pem_file = ecalloc(1, MAXPATHLEN);
19611965

19621966
#if PHP_VERSION_ID >= 70000
1963-
zend_string *s = zval_get_string(pem);
1964-
if (VCWD_REALPATH(ZSTR_VAL(s), filename)) {
1967+
if (VCWD_REALPATH(ZSTR_VAL(s), manager->pem_file)) {
19651968
#else
1966-
convert_to_string_ex(pem);
1967-
if (VCWD_REALPATH(Z_STRVAL_PP(pem), filename)) {
1969+
if (VCWD_REALPATH(Z_STRVAL_PP(pem), manager->pem_file)) {
19681970
#endif
1969-
mongoc_ssl_opt_t ssl_options;
1971+
mongoc_ssl_opt_t ssl_options = {0};
19701972

1971-
ssl_options.pem_file = filename;
1973+
ssl_options.pem_file = manager->pem_file;
19721974
mongoc_client_set_ssl_opts(client, &ssl_options);
19731975
}
19741976
#if PHP_VERSION_ID >= 70000
@@ -1999,7 +2001,7 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
19992001
return false;
20002002
}
20012003

2002-
manager->client = php_phongo_make_mongo_client(uri, driverOptions TSRMLS_CC);
2004+
manager->client = php_phongo_make_mongo_client(manager, uri, driverOptions TSRMLS_CC);
20032005
mongoc_uri_destroy(uri);
20042006

20052007
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
@@ -380,6 +380,10 @@ static void php_phongo_manager_free_object(phongo_free_object_arg *object TSRMLS
380380
mongoc_client_destroy(intern->client);
381381
}
382382

383+
if (intern->pem_file) {
384+
efree(intern->pem_file);
385+
}
386+
383387
#if PHP_VERSION_ID < 70000
384388
efree(intern);
385389
#endif

0 commit comments

Comments
 (0)