@@ -278,6 +278,11 @@ static void _free_result(zend_resource *rsrc)
278
278
}
279
279
/* }}} */
280
280
281
+ static void release_string (zend_resource * rsrc )
282
+ {
283
+ zend_string_release ((zend_string * ) rsrc -> ptr );
284
+ }
285
+
281
286
static bool _php_pgsql_identifier_is_escaped (const char * identifier , size_t len ) /* {{{ */
282
287
{
283
288
/* Handle edge case. Cannot be a escaped string */
@@ -351,7 +356,7 @@ PHP_MINIT_FUNCTION(pgsql)
351
356
le_plink = zend_register_list_destructors_ex (NULL , _close_pgsql_plink , "pgsql link persistent" , module_number );
352
357
le_result = zend_register_list_destructors_ex (_free_result , NULL , "pgsql result" , module_number );
353
358
le_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 );
355
360
/* libpq version */
356
361
php_libpq_version (buf , sizeof (buf ));
357
362
REGISTER_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)
1476
1481
}
1477
1482
1478
1483
/* {{{ 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 )
1480
1485
{
1481
1486
smart_str str = {0 };
1482
1487
zend_resource * field_type ;
1483
- char * ret = NULL ;
1488
+ zend_string * ret = NULL ;
1484
1489
1485
1490
/* try to lookup the type in the resource list */
1486
1491
smart_str_appends (& str , "pgsql_oid_" );
1487
1492
smart_str_append_unsigned (& str , oid );
1488
1493
smart_str_0 (& str );
1489
1494
1490
1495
if ((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 );
1492
1497
} else { /* hash all oid's */
1493
1498
int i , num_rows ;
1494
1499
int oid_offset ,name_offset ;
@@ -1501,7 +1506,7 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list)
1501
1506
PQclear (result );
1502
1507
}
1503
1508
smart_str_free (& str );
1504
- return estrndup ( "" , sizeof ( "" ) - 1 );
1509
+ return ZSTR_EMPTY_ALLOC ( );
1505
1510
}
1506
1511
num_rows = PQntuples (result );
1507
1512
oid_offset = PQfnumber (result ,"oid" );
@@ -1521,10 +1526,10 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list)
1521
1526
continue ;
1522
1527
}
1523
1528
new_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 );
1525
1530
zend_hash_update_mem (list , str .s , (void * ) & new_oid_entry , sizeof (zend_resource ));
1526
1531
if (!ret && strtoul (tmp_oid , & end_ptr , 10 )== oid ) {
1527
- ret = estrdup ( tmp_name );
1532
+ ret = zend_string_copy ( new_oid_entry . ptr );
1528
1533
}
1529
1534
}
1530
1535
PQclear (result );
@@ -1582,7 +1587,7 @@ PHP_FUNCTION(pg_field_table)
1582
1587
1583
1588
if ((field_table = zend_hash_find_ptr (& EG (regular_list ), hash_key .s )) != NULL ) {
1584
1589
smart_str_free (& hash_key );
1585
- RETURN_STRING (( char * )field_table -> ptr );
1590
+ RETURN_STR_COPY (( zend_string * )field_table -> ptr );
1586
1591
} else { /* Not found, lookup by querying PostgreSQL system tables */
1587
1592
PGresult * tmp_res ;
1588
1593
smart_str querystr = {0 };
@@ -1610,12 +1615,12 @@ PHP_FUNCTION(pg_field_table)
1610
1615
}
1611
1616
1612
1617
new_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 );
1614
1619
zend_hash_update_mem (& EG (regular_list ), hash_key .s , (void * )& new_field_table , sizeof (zend_resource ));
1615
1620
1616
1621
smart_str_free (& hash_key );
1617
1622
PQclear (tmp_res );
1618
- RETURN_STRING ( table_name );
1623
+ RETURN_STR_COPY ( new_field_table . ptr );
1619
1624
}
1620
1625
1621
1626
}
@@ -1662,11 +1667,9 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ
1662
1667
case PHP_PG_FIELD_SIZE :
1663
1668
RETURN_LONG (PQfsize (pgsql_result , (int )field ));
1664
1669
break ;
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 )));
1670
1673
break ;
1671
1674
case PHP_PG_FIELD_TYPE_OID :
1672
1675
0 commit comments