Skip to content

Commit b65ee36

Browse files
committed
PHPC-1500: Store client hash in manager struct
1 parent d3a0983 commit b65ee36

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

php_phongo.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ static char* php_phongo_manager_make_client_hash(const char* uri_string, zval* o
25482548

25492549
if (!EG(exception)) {
25502550
*hash_len = ZSTR_LEN(var_buf.s);
2551-
hash = pestrndup(ZSTR_VAL(var_buf.s), *hash_len, 1);
2551+
hash = estrndup(ZSTR_VAL(var_buf.s), *hash_len);
25522552
}
25532553

25542554
zval_ptr_dtor(&args);
@@ -2580,7 +2580,7 @@ static char* php_phongo_manager_make_client_hash(const char* uri_string, zval* o
25802580

25812581
if (!EG(exception)) {
25822582
*hash_len = var_buf.len;
2583-
hash = pestrndup(var_buf.c, *hash_len, 1);
2583+
hash = estrndup(var_buf.c, *hash_len);
25842584
}
25852585

25862586
zval_ptr_dtor(&args);
@@ -2655,21 +2655,19 @@ static mongoc_client_t* php_phongo_find_client(const char* hash, size_t hash_len
26552655

26562656
void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string, zval* options, zval* driverOptions TSRMLS_DC) /* {{{ */
26572657
{
2658-
char* hash = NULL;
2659-
size_t hash_len = 0;
26602658
bson_t bson_options = BSON_INITIALIZER;
26612659
mongoc_uri_t* uri = NULL;
26622660
#ifdef MONGOC_ENABLE_SSL
26632661
mongoc_ssl_opt_t* ssl_opt = NULL;
26642662
#endif
26652663

2666-
if (!(hash = php_phongo_manager_make_client_hash(uri_string, options, driverOptions, &hash_len TSRMLS_CC))) {
2664+
if (!(manager->client_hash = php_phongo_manager_make_client_hash(uri_string, options, driverOptions, &manager->client_hash_len TSRMLS_CC))) {
26672665
/* Exception should already have been thrown and there is nothing to free */
26682666
return;
26692667
}
26702668

2671-
if ((manager->client = php_phongo_find_client(hash, hash_len TSRMLS_CC))) {
2672-
MONGOC_DEBUG("Found client for hash: %s\n", hash);
2669+
if ((manager->client = php_phongo_find_client(manager->client_hash, manager->client_hash_len TSRMLS_CC))) {
2670+
MONGOC_DEBUG("Found client for hash: %s\n", manager->client_hash);
26732671
goto cleanup;
26742672
}
26752673

@@ -2733,14 +2731,10 @@ void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string,
27332731
}
27342732
#endif
27352733

2736-
MONGOC_DEBUG("Created client hash: %s\n", hash);
2737-
php_phongo_persist_client(hash, hash_len, manager->client TSRMLS_CC);
2734+
MONGOC_DEBUG("Created client hash: %s\n", manager->client_hash);
2735+
php_phongo_persist_client(manager->client_hash, manager->client_hash_len, manager->client TSRMLS_CC);
27382736

27392737
cleanup:
2740-
if (hash) {
2741-
pefree(hash, 1);
2742-
}
2743-
27442738
bson_destroy(&bson_options);
27452739

27462740
if (uri) {

php_phongo_structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ typedef struct {
8080
PHONGO_ZEND_OBJECT_PRE
8181
mongoc_client_t* client;
8282
int created_by_pid;
83+
char* client_hash;
84+
size_t client_hash_len;
8385
PHONGO_ZEND_OBJECT_POST
8486
} php_phongo_manager_t;
8587

src/MongoDB/Manager.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,10 @@ static void php_phongo_manager_free_object(phongo_free_object_arg* object TSRMLS
866866
intern->client = NULL;
867867
}
868868

869+
if (intern->client_hash) {
870+
efree(intern->client_hash);
871+
}
872+
869873
#if PHP_VERSION_ID < 70000
870874
efree(intern);
871875
#endif

0 commit comments

Comments
 (0)