@@ -160,22 +160,17 @@ static zend_function *pgsql_link_get_constructor(zend_object *object) {
160160static void pgsql_link_free (pgsql_link_handle * link )
161161{
162162 PGresult * res ;
163- zval * hash ;
164163
165164 while ((res = PQgetResult (link -> conn ))) {
166165 PQclear (res );
167166 }
168167 PQfinish (link -> conn );
169168 PGG (num_links )-- ;
170169
171- /* Remove connection hash for this link */
172- hash = zend_hash_index_find (& PGG (hashes ), (uintptr_t ) link -> conn );
173- if (hash ) {
174- zend_hash_index_del (& PGG (hashes ), (uintptr_t ) link -> conn );
175- zend_hash_del (& PGG (regular_list ), Z_STR_P (hash ));
176- }
170+ zend_hash_del (& PGG (regular_list ), link -> hash );
177171
178172 link -> conn = NULL ;
173+ zend_string_release (link -> hash );
179174}
180175
181176static void pgsql_link_free_obj (zend_object * obj )
@@ -406,7 +401,6 @@ static PHP_GINIT_FUNCTION(pgsql)
406401 memset (pgsql_globals , 0 , sizeof (zend_pgsql_globals ));
407402 /* Initialize notice message hash at MINIT only */
408403 zend_hash_init (& pgsql_globals -> notices , 0 , NULL , ZVAL_PTR_DTOR , 1 );
409- zend_hash_init (& pgsql_globals -> hashes , 0 , NULL , ZVAL_PTR_DTOR , 1 );
410404 zend_hash_init (& pgsql_globals -> regular_list , 0 , NULL , ZVAL_PTR_DTOR , 1 );
411405}
412406
@@ -578,7 +572,6 @@ PHP_MSHUTDOWN_FUNCTION(pgsql)
578572{
579573 UNREGISTER_INI_ENTRIES ();
580574 zend_hash_destroy (& PGG (notices ));
581- zend_hash_destroy (& PGG (hashes ));
582575 zend_hash_destroy (& PGG (regular_list ));
583576
584577 return SUCCESS ;
@@ -763,6 +756,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
763756 object_init_ex (return_value , pgsql_link_ce );
764757 link = Z_PGSQL_LINK_P (return_value );
765758 link -> conn = pgsql ;
759+ link -> hash = zend_string_copy (str .s );
766760
767761 /* add it to the hash */
768762 ZVAL_COPY (& new_index_ptr , return_value );
@@ -772,11 +766,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
772766 * when the connection is closed. This uses the address of the connection rather than the
773767 * zend_resource, because the resource destructor is passed a stack copy of the resource
774768 * structure. */
775- {
776- zval tmp ;
777- ZVAL_STR_COPY (& tmp , str .s );
778- zend_hash_index_update (& PGG (hashes ), (uintptr_t ) pgsql , & tmp );
779- }
769+
780770 PGG (num_links )++ ;
781771 }
782772 /* set notice processor */
0 commit comments