@@ -278,6 +278,11 @@ static void _free_result(zend_resource *rsrc)
278278}
279279/* }}} */
280280
281+ static void release_string (zend_resource * rsrc )
282+ {
283+ zend_string_release ((zend_string * ) rsrc -> ptr );
284+ }
285+
281286static bool _php_pgsql_identifier_is_escaped (const char * identifier , size_t len ) /* {{{ */
282287{
283288/* Handle edge case. Cannot be a escaped string */
@@ -351,7 +356,7 @@ PHP_MINIT_FUNCTION(pgsql)
351356le_plink = zend_register_list_destructors_ex (NULL , _close_pgsql_plink , "pgsql link persistent" , module_number );
352357le_result = zend_register_list_destructors_ex (_free_result , NULL , "pgsql result" , module_number );
353358le_lofp = zend_register_list_destructors_ex (_free_ptr , NULL , "pgsql large object" , module_number );
354- le_string = zend_register_list_destructors_ex (_free_ptr , NULL , "pgsql string" , module_number );
359+ le_string = zend_register_list_destructors_ex (release_string , NULL , "pgsql string" , module_number );
355360/* libpq version */
356361php_libpq_version (buf , sizeof (buf ));
357362REGISTER_STRING_CONSTANT ("PGSQL_LIBPQ_VERSION" , buf , CONST_CS | CONST_PERSISTENT );
@@ -1476,19 +1481,19 @@ static inline bool is_valid_oid_string(zend_string *oid, Oid *return_oid)
14761481}
14771482
14781483/* {{{ get_field_name */
1479- static char * get_field_name (PGconn * pgsql , Oid oid , HashTable * list )
1484+ static zend_string * get_field_name (PGconn * pgsql , Oid oid , HashTable * list )
14801485{
14811486smart_str str = {0 };
14821487zend_resource * field_type ;
1483- char * ret = NULL ;
1488+ zend_string * ret = NULL ;
14841489
14851490/* try to lookup the type in the resource list */
14861491smart_str_appends (& str , "pgsql_oid_" );
14871492smart_str_append_unsigned (& str , oid );
14881493smart_str_0 (& str );
14891494
14901495if ((field_type = zend_hash_find_ptr (list , str .s )) != NULL ) {
1491- ret = estrdup (( char * )field_type -> ptr );
1496+ ret = zend_string_copy (( zend_string * ) field_type -> ptr );
14921497} else { /* hash all oid's */
14931498int i , num_rows ;
14941499int oid_offset ,name_offset ;
@@ -1501,7 +1506,7 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list)
15011506PQclear (result );
15021507}
15031508smart_str_free (& str );
1504- return estrndup ( "" , sizeof ( "" ) - 1 );
1509+ return ZSTR_EMPTY_ALLOC ( );
15051510}
15061511num_rows = PQntuples (result );
15071512oid_offset = PQfnumber (result ,"oid" );
@@ -1521,10 +1526,10 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list)
15211526continue ;
15221527}
15231528new_oid_entry .type = le_string ;
1524- new_oid_entry .ptr = estrdup (tmp_name );
1529+ new_oid_entry .ptr = zend_string_init (tmp_name , strlen ( tmp_name ), 0 );
15251530zend_hash_update_mem (list , str .s , (void * ) & new_oid_entry , sizeof (zend_resource ));
15261531if (!ret && strtoul (tmp_oid , & end_ptr , 10 )== oid ) {
1527- ret = estrdup ( tmp_name );
1532+ ret = zend_string_copy ( new_oid_entry . ptr );
15281533}
15291534}
15301535PQclear (result );
@@ -1582,7 +1587,7 @@ PHP_FUNCTION(pg_field_table)
15821587
15831588if ((field_table = zend_hash_find_ptr (& EG (regular_list ), hash_key .s )) != NULL ) {
15841589smart_str_free (& hash_key );
1585- RETURN_STRING (( char * )field_table -> ptr );
1590+ RETURN_STR_COPY (( zend_string * )field_table -> ptr );
15861591} else { /* Not found, lookup by querying PostgreSQL system tables */
15871592PGresult * tmp_res ;
15881593smart_str querystr = {0 };
@@ -1610,12 +1615,12 @@ PHP_FUNCTION(pg_field_table)
16101615}
16111616
16121617new_field_table .type = le_string ;
1613- new_field_table .ptr = estrdup (table_name );
1618+ new_field_table .ptr = zend_string_init (table_name , strlen ( table_name ), 0 );
16141619zend_hash_update_mem (& EG (regular_list ), hash_key .s , (void * )& new_field_table , sizeof (zend_resource ));
16151620
16161621smart_str_free (& hash_key );
16171622PQclear (tmp_res );
1618- RETURN_STRING ( table_name );
1623+ RETURN_STR_COPY ( new_field_table . ptr );
16191624}
16201625
16211626}
@@ -1662,11 +1667,9 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ
16621667case PHP_PG_FIELD_SIZE :
16631668RETURN_LONG (PQfsize (pgsql_result , (int )field ));
16641669break ;
1665- case PHP_PG_FIELD_TYPE : {
1666- char * name = get_field_name (pg_result -> conn , PQftype (pgsql_result , (int )field ), & EG (regular_list ));
1667- RETVAL_STRING (name );
1668- efree (name );
1669- }
1670+ case PHP_PG_FIELD_TYPE :
1671+ RETURN_STR (get_field_name (
1672+ pg_result -> conn , PQftype (pgsql_result , (int )field ), & EG (regular_list )));
16701673break ;
16711674case PHP_PG_FIELD_TYPE_OID :
16721675
0 commit comments