@@ -83,7 +83,7 @@ static int resend_auth(RedisSock *redis_sock TSRMLS_DC) {
8383 int cmd_len , response_len ;
8484
8585 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 ));
8787
8888 if (redis_sock_write (redis_sock , cmd , cmd_len TSRMLS_CC ) < 0 ) {
8989 efree (cmd );
@@ -117,11 +117,11 @@ static void
117117redis_error_throw (RedisSock * redis_sock TSRMLS_DC )
118118{
119119 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
123123 ) {
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 );
125125 }
126126}
127127
@@ -1367,7 +1367,7 @@ redis_sock_create(char *host, int host_len, unsigned short port,
13671367 RedisSock * redis_sock ;
13681368
13691369 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 );
13711371 redis_sock -> stream = NULL ;
13721372 redis_sock -> status = REDIS_SOCK_STATUS_DISCONNECTED ;
13731373 redis_sock -> watching = 0 ;
@@ -1377,8 +1377,8 @@ redis_sock_create(char *host, int host_len, unsigned short port,
13771377 redis_sock -> lazy_connect = lazy_connect ;
13781378 redis_sock -> persistent_id = NULL ;
13791379
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 );
13821382 }
13831383
13841384 redis_sock -> port = port ;
@@ -1394,7 +1394,6 @@ redis_sock_create(char *host, int host_len, unsigned short port,
13941394 redis_sock -> pipeline_len = 0 ;
13951395
13961396 redis_sock -> err = NULL ;
1397- redis_sock -> err_len = 0 ;
13981397
13991398 redis_sock -> scan = REDIS_SCAN_NORETRY ;
14001399
@@ -1428,8 +1427,8 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
14281427 read_tv .tv_sec = (time_t )redis_sock -> read_timeout ;
14291428 read_tv .tv_usec = (int )((redis_sock -> read_timeout - read_tv .tv_sec )* 1000000 );
14301429
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 ) );
14331432 usocket = 1 ;
14341433 } else {
14351434 if (redis_sock -> port == 0 )
@@ -1438,17 +1437,17 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
14381437#ifdef HAVE_IPV6
14391438 /* If we've got IPv6 and find a colon in our address, convert to proper
14401439 * IPv6 [host]:port format */
1441- if (strchr (redis_sock -> host , ':' ) != NULL ) {
1440+ if (strchr (ZSTR_VAL ( redis_sock -> host ) , ':' ) != NULL ) {
14421441 fmtstr = "[%s]:%d" ;
14431442 }
14441443#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 );
14461445 }
14471446
14481447 if (redis_sock -> persistent ) {
14491448 if (redis_sock -> persistent_id ) {
14501449 spprintf (& persistent_id , 0 , "phpredis:%s:%s" , host ,
1451- redis_sock -> persistent_id );
1450+ ZSTR_VAL ( redis_sock -> persistent_id ) );
14521451 } else {
14531452 spprintf (& persistent_id , 0 , "phpredis:%s:%f" , host ,
14541453 redis_sock -> timeout );
@@ -1541,17 +1540,13 @@ redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len)
15411540{
15421541 // Free our last error
15431542 if (redis_sock -> err != NULL ) {
1544- efree (redis_sock -> err );
1543+ zend_string_release (redis_sock -> err );
1544+ redis_sock -> err = NULL ;
15451545 }
15461546
15471547 if (msg != NULL && msg_len > 0 ) {
15481548 // 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 );
15551550 }
15561551}
15571552
@@ -1759,22 +1754,24 @@ redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz TSRMLS_DC)
17591754 */
17601755PHP_REDIS_API void redis_free_socket (RedisSock * redis_sock )
17611756{
1762- if (redis_sock -> prefix ) {
1763- efree (redis_sock -> prefix );
1757+ if (redis_sock -> prefix ) {
1758+ zend_string_release (redis_sock -> prefix );
17641759 }
17651760 if (redis_sock -> pipeline_cmd ) {
17661761 efree (redis_sock -> pipeline_cmd );
17671762 }
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 );
17701768 }
1771- if (redis_sock -> auth ) {
1772- efree (redis_sock -> auth );
1769+ if (redis_sock -> persistent_id ) {
1770+ zend_string_release (redis_sock -> persistent_id );
17731771 }
1774- if (redis_sock -> persistent_id ) {
1775- efree (redis_sock -> persistent_id );
1772+ if (redis_sock -> host ) {
1773+ zend_string_release (redis_sock -> host );
17761774 }
1777- efree (redis_sock -> host );
17781775 efree (redis_sock );
17791776}
17801777
@@ -1931,14 +1928,14 @@ redis_key_prefix(RedisSock *redis_sock, char **key, strlen_t *key_len) {
19311928 int ret_len ;
19321929 char * ret ;
19331930
1934- if (redis_sock -> prefix == NULL || redis_sock -> prefix_len == 0 ) {
1931+ if (redis_sock -> prefix == NULL ) {
19351932 return 0 ;
19361933 }
19371934
1938- ret_len = redis_sock -> prefix_len + * key_len ;
1935+ ret_len = ZSTR_LEN ( redis_sock -> prefix ) + * key_len ;
19391936 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 );
19421939
19431940 * key = ret ;
19441941 * key_len = ret_len ;
0 commit comments