@@ -83,7 +83,7 @@ static int resend_auth(RedisSock *redis_sock TSRMLS_DC) {
83
83
int cmd_len , response_len ;
84
84
85
85
cmd_len = redis_spprintf (redis_sock , NULL TSRMLS_CC , & cmd , "AUTH" , "s" ,
86
- redis_sock -> auth , strlen (redis_sock -> auth ));
86
+ ZSTR_VAL ( redis_sock -> auth ), ZSTR_LEN (redis_sock -> auth ));
87
87
88
88
if (redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC ) < 0 ) {
89
89
efree (cmd );
@@ -117,11 +117,11 @@ static void
117
117
redis_error_throw (RedisSock * redis_sock TSRMLS_DC )
118
118
{
119
119
if (redis_sock != NULL && redis_sock -> err != NULL &&
120
- memcmp (redis_sock -> err , "ERR" , sizeof ("ERR" ) - 1 ) != 0 &&
121
- memcmp (redis_sock -> err , "NOSCRIPT" , sizeof ("NOSCRIPT" ) - 1 ) != 0 &&
122
- memcmp (redis_sock -> err , "WRONGTYPE" , sizeof ("WRONGTYPE" ) - 1 ) != 0
120
+ memcmp (ZSTR_VAL ( redis_sock -> err ) , "ERR" , sizeof ("ERR" ) - 1 ) != 0 &&
121
+ memcmp (ZSTR_VAL ( redis_sock -> err ) , "NOSCRIPT" , sizeof ("NOSCRIPT" ) - 1 ) != 0 &&
122
+ memcmp (ZSTR_VAL ( redis_sock -> err ) , "WRONGTYPE" , sizeof ("WRONGTYPE" ) - 1 ) != 0
123
123
) {
124
- zend_throw_exception (redis_exception_ce , redis_sock -> err , 0 TSRMLS_CC );
124
+ zend_throw_exception (redis_exception_ce , ZSTR_VAL ( redis_sock -> err ) , 0 TSRMLS_CC );
125
125
}
126
126
}
127
127
@@ -1367,7 +1367,7 @@ redis_sock_create(char *host, int host_len, unsigned short port,
1367
1367
RedisSock * redis_sock ;
1368
1368
1369
1369
redis_sock = ecalloc (1 , sizeof (RedisSock ));
1370
- redis_sock -> host = estrndup (host , host_len );
1370
+ redis_sock -> host = zend_string_init (host , host_len , 0 );
1371
1371
redis_sock -> stream = NULL ;
1372
1372
redis_sock -> status = REDIS_SOCK_STATUS_DISCONNECTED ;
1373
1373
redis_sock -> watching = 0 ;
@@ -1377,8 +1377,8 @@ redis_sock_create(char *host, int host_len, unsigned short port,
1377
1377
redis_sock -> lazy_connect = lazy_connect ;
1378
1378
redis_sock -> persistent_id = NULL ;
1379
1379
1380
- if (persistent_id ) {
1381
- redis_sock -> persistent_id = estrdup (persistent_id );
1380
+ if (persistent_id ) {
1381
+ redis_sock -> persistent_id = zend_string_init (persistent_id , strlen ( persistent_id ), 0 );
1382
1382
}
1383
1383
1384
1384
redis_sock -> port = port ;
@@ -1394,7 +1394,6 @@ redis_sock_create(char *host, int host_len, unsigned short port,
1394
1394
redis_sock -> pipeline_len = 0 ;
1395
1395
1396
1396
redis_sock -> err = NULL ;
1397
- redis_sock -> err_len = 0 ;
1398
1397
1399
1398
redis_sock -> scan = REDIS_SCAN_NORETRY ;
1400
1399
@@ -1428,8 +1427,8 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
1428
1427
read_tv .tv_sec = (time_t )redis_sock -> read_timeout ;
1429
1428
read_tv .tv_usec = (int )((redis_sock -> read_timeout - read_tv .tv_sec )* 1000000 );
1430
1429
1431
- if ( redis_sock -> host [0 ] == '/' && redis_sock -> port < 1 ) {
1432
- host_len = snprintf (host , sizeof (host ), "unix://%s" , redis_sock -> host );
1430
+ if ( ZSTR_VAL ( redis_sock -> host ) [0 ] == '/' && redis_sock -> port < 1 ) {
1431
+ host_len = snprintf (host , sizeof (host ), "unix://%s" , ZSTR_VAL ( redis_sock -> host ) );
1433
1432
usocket = 1 ;
1434
1433
} else {
1435
1434
if (redis_sock -> port == 0 )
@@ -1438,17 +1437,17 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
1438
1437
#ifdef HAVE_IPV6
1439
1438
/* If we've got IPv6 and find a colon in our address, convert to proper
1440
1439
* IPv6 [host]:port format */
1441
- if (strchr (redis_sock -> host , ':' ) != NULL ) {
1440
+ if (strchr (ZSTR_VAL ( redis_sock -> host ) , ':' ) != NULL ) {
1442
1441
fmtstr = "[%s]:%d" ;
1443
1442
}
1444
1443
#endif
1445
- host_len = snprintf (host , sizeof (host ), fmtstr , redis_sock -> host , redis_sock -> port );
1444
+ host_len = snprintf (host , sizeof (host ), fmtstr , ZSTR_VAL ( redis_sock -> host ) , redis_sock -> port );
1446
1445
}
1447
1446
1448
1447
if (redis_sock -> persistent ) {
1449
1448
if (redis_sock -> persistent_id ) {
1450
1449
spprintf (& persistent_id , 0 , "phpredis:%s:%s" , host ,
1451
- redis_sock -> persistent_id );
1450
+ ZSTR_VAL ( redis_sock -> persistent_id ) );
1452
1451
} else {
1453
1452
spprintf (& persistent_id , 0 , "phpredis:%s:%f" , host ,
1454
1453
redis_sock -> timeout );
@@ -1541,17 +1540,13 @@ redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len)
1541
1540
{
1542
1541
// Free our last error
1543
1542
if (redis_sock -> err != NULL ) {
1544
- efree (redis_sock -> err );
1543
+ zend_string_release (redis_sock -> err );
1544
+ redis_sock -> err = NULL ;
1545
1545
}
1546
1546
1547
1547
if (msg != NULL && msg_len > 0 ) {
1548
1548
// Copy in our new error message
1549
- redis_sock -> err = estrndup (msg , msg_len );
1550
- redis_sock -> err_len = msg_len ;
1551
- } else {
1552
- // Set to null, with zero length
1553
- redis_sock -> err = NULL ;
1554
- redis_sock -> err_len = 0 ;
1549
+ redis_sock -> err = zend_string_init (msg , msg_len , 0 );
1555
1550
}
1556
1551
}
1557
1552
@@ -1759,22 +1754,24 @@ redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz TSRMLS_DC)
1759
1754
*/
1760
1755
PHP_REDIS_API void redis_free_socket (RedisSock * redis_sock )
1761
1756
{
1762
- if (redis_sock -> prefix ) {
1763
- efree (redis_sock -> prefix );
1757
+ if (redis_sock -> prefix ) {
1758
+ zend_string_release (redis_sock -> prefix );
1764
1759
}
1765
1760
if (redis_sock -> pipeline_cmd ) {
1766
1761
efree (redis_sock -> pipeline_cmd );
1767
1762
}
1768
- if (redis_sock -> err ) {
1769
- efree (redis_sock -> err );
1763
+ if (redis_sock -> err ) {
1764
+ zend_string_release (redis_sock -> err );
1765
+ }
1766
+ if (redis_sock -> auth ) {
1767
+ zend_string_release (redis_sock -> auth );
1770
1768
}
1771
- if (redis_sock -> auth ) {
1772
- efree (redis_sock -> auth );
1769
+ if (redis_sock -> persistent_id ) {
1770
+ zend_string_release (redis_sock -> persistent_id );
1773
1771
}
1774
- if (redis_sock -> persistent_id ) {
1775
- efree (redis_sock -> persistent_id );
1772
+ if (redis_sock -> host ) {
1773
+ zend_string_release (redis_sock -> host );
1776
1774
}
1777
- efree (redis_sock -> host );
1778
1775
efree (redis_sock );
1779
1776
}
1780
1777
@@ -1931,14 +1928,14 @@ redis_key_prefix(RedisSock *redis_sock, char **key, strlen_t *key_len) {
1931
1928
int ret_len ;
1932
1929
char * ret ;
1933
1930
1934
- if (redis_sock -> prefix == NULL || redis_sock -> prefix_len == 0 ) {
1931
+ if (redis_sock -> prefix == NULL ) {
1935
1932
return 0 ;
1936
1933
}
1937
1934
1938
- ret_len = redis_sock -> prefix_len + * key_
57AE
len ;
1935
+ ret_len = ZSTR_LEN ( redis_sock -> prefix ) + * key_len ;
1939
1936
ret = ecalloc (1 + ret_len , 1 );
1940
- memcpy (ret , redis_sock -> prefix , redis_sock -> prefix_len );
1941
- memcpy (ret + redis_sock -> prefix_len , * key , * key_len );
1937
+ memcpy (ret , ZSTR_VAL ( redis_sock -> prefix ), ZSTR_LEN ( redis_sock -> prefix ) );
1938
+ memcpy (ret + ZSTR_LEN ( redis_sock -> prefix ) , * key , * key_len );
1942
1939
1943
1940
* key = ret ;
1944
1941
* key_len = ret_len ;
0 commit comments