@@ -148,11 +148,7 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
148148 if ((MULTI == redis_sock -> mode ) || redis_sock -> watching || count == 10 ) {
149149 /* too many failures */
150150 if (redis_sock -> stream ) { /* close stream if still here */
151- redis_stream_close (redis_sock TSRMLS_CC );
152- redis_sock -> stream = NULL ;
153- redis_sock -> mode = ATOMIC ;
154- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
155- redis_sock -> watching = 0 ;
151+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
156152 }
157153 if (!no_throw ) {
158154 zend_throw_exception (redis_exception_ce , "Connection lost" ,
@@ -411,11 +407,7 @@ redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
411407 }
412408
413409 if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
414- redis_stream_close (redis_sock TSRMLS_CC );
415- redis_sock -> stream = NULL ;
416- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
417- redis_sock -> mode = ATOMIC ;
418- redis_sock -> watching = 0 ;
410+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
419411 zend_throw_exception (redis_exception_ce ,
420412 "read error on connection" , 0 TSRMLS_CC );
421413 return ;
@@ -478,12 +470,8 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
478470 }
479471
480472 if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
481- redis_stream_close (redis_sock TSRMLS_CC );
482- redis_sock -> stream = NULL ;
483- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
484- redis_sock -> mode = ATOMIC ;
485- redis_sock -> watching = 0 ;
486- zend_throw_exception (redis_exception_ce , "read error on connection" ,
473+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
474+ zend_throw_exception (redis_exception_ce , "read error on connection" ,
487475 0 TSRMLS_CC );
488476 return NULL ;
489477 }
@@ -504,8 +492,7 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
504492 return NULL ;
505493 case '$' :
506494 * buf_len = atoi (inbuf + 1 );
507- resp = redis_sock_read_bulk_reply (redis_sock , * buf_len TSRMLS_CC );
508- return resp ;
495+ return redis_sock_read_bulk_reply (redis_sock , * buf_len TSRMLS_CC );
509496
510497 case '*' :
511498 /* For null multi-bulk replies (like timeouts from brpoplpush): */
@@ -521,10 +508,7 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
521508 /* :123\r\n */
522509 * buf_len = strlen (inbuf ) - 2 ;
523510 if (* buf_len >= 2 ) {
524- resp = emalloc (1 + * buf_len );
525- memcpy (resp , inbuf , * buf_len );
526- resp [* buf_len ] = 0 ;
527- return resp ;
511+ return estrndup (inbuf , * buf_len );
528512 }
529513 default :
530514 zend_throw_exception_ex (
@@ -1026,14 +1010,10 @@ PHP_REDIS_API void redis_parse_client_list_response(char *response, zval *z_resu
10261010 have a key and value, but check anyway. */
10271011 if (kpos && vpos ) {
10281012 /* Allocate, copy in our key */
1029- key = emalloc (klen + 1 );
1030- strncpy (key , kpos , klen );
1031- key [klen ] = 0 ;
1013+ key = estrndup (kpos , klen );
10321014
10331015 /* Allocate, copy in our value */
1034- value = emalloc (p - lpos + 1 );
1035- strncpy (value ,lpos ,p - lpos + 1 );
1036- value [p - lpos ]= 0 ;
1016+ value = estrndup (lpos , p - lpos );
10371017
10381018 /* Treat numbers as numbers, strings as strings */
10391019 is_numeric = 1 ;
@@ -1270,11 +1250,7 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
12701250 return -1 ;
12711251 }
12721252 if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1273- redis_stream_close (redis_sock TSRMLS_CC );
1274- redis_sock -> stream = NULL ;
1275- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1276- redis_sock -> mode = ATOMIC ;
1277- redis_sock -> watching = 0 ;
1253+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
12781254 zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
12791255 return -1 ;
12801256 }
@@ -1515,18 +1491,12 @@ redis_sock_create(char *host, int host_len, unsigned short port, double timeout,
15151491 redis_sock -> retry_interval = retry_interval * 1000 ;
15161492 redis_sock -> persistent = persistent ;
15171493 redis_sock -> lazy_connect = lazy_connect ;
1494+ redis_sock -> persistent_id = NULL ;
15181495
15191496 if (persistent_id ) {
1520- size_t persistent_id_len = strlen (persistent_id );
1521- redis_sock -> persistent_id = ecalloc (persistent_id_len + 1 , 1 );
1522- memcpy (redis_sock -> persistent_id , persistent_id , persistent_id_len );
1523- } else {
1524- redis_sock -> persistent_id = NULL ;
1497+ redis_sock -> persistent_id = estrdup (persistent_id );
15251498 }
15261499
1527- memcpy (redis_sock -> host , host , host_len );
1528- redis_sock -> host [host_len ] = '\0' ;
1529-
15301500 redis_sock -> port = port ;
15311501 redis_sock -> timeout = timeout ;
15321502 redis_sock -> read_timeout = timeout ;
@@ -1762,12 +1732,8 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
17621732 return -1 ;
17631733 }
17641734 if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1765- redis_stream_close (redis_sock TSRMLS_CC );
1766- redis_sock -> stream = NULL ;
1767- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1768- redis_sock -> mode = ATOMIC ;
1769- redis_sock -> watching = 0 ;
1770- zend_throw_exception (redis_exception_ce , "read error on connection" , 0
1735+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1736+ zend_throw_exception (redis_exception_ce , "read error on connection" , 0
17711737 TSRMLS_CC );
17721738 return -1 ;
17731739 }
@@ -1811,11 +1777,7 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
18111777 return -1 ;
18121778 }
18131779 if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1814- redis_stream_close (redis_sock TSRMLS_CC );
1815- redis_sock -> stream = NULL ;
1816- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1817- redis_sock -> mode = ATOMIC ;
1818- redis_sock -> watching = 0 ;
1780+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
18191781 zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
18201782 return -1 ;
18211783 }
@@ -1895,11 +1857,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
18951857 return -1 ;
18961858 }
18971859 if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1898- redis_stream_close (redis_sock TSRMLS_CC );
1899- redis_sock -> stream = NULL ;
1900- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1901- redis_sock -> mode = ATOMIC ;
1902- redis_sock -> watching = 0 ;
1860+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
19031861 zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
19041862 return -1 ;
19051863 }
@@ -2119,11 +2077,7 @@ redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size,
21192077 == NULL )
21202078 {
21212079 // Close, put our socket state into error
2122- redis_stream_close (redis_sock TSRMLS_CC );
2123- redis_sock -> stream = NULL ;
2124- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
2125- redis_sock -> mode = ATOMIC ;
2126- redis_sock -> watching = 0 ;
2080+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
21272081
21282082 // Throw a read error exception
21292083 zend_throw_exception (redis_exception_ce , "read error on connection" ,
@@ -2346,4 +2300,4 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
23462300 return 0 ;
23472301}
23482302
2349- /* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
2303+ /* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */
0 commit comments