Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 335c058

Browse files
Use zend_list_close instead of zend_list_delete when reconnecting.
In php7 zend_list_close handles closing the connection and frees resource structures but doesn't decrease refcount (and therefore remove the element from the list). This segfault could be triggered in php7 by simply doing this: ```php $r = new Redis(); $r->connect('localhost', 6379); $r->connect('localhost', 6379); $r->ping(); // or any other command ``` What appears to have been happening here, is that phpredis would delete any existing socket resource on a connect call to an already existing object, but then the call to add_property_resource would trigger the destructor of the socket (as the Zend library already saw a "socket" property). This would set redis_sock->stream->abstract (the actual socket) to NULL, causing any subsequent communication to segfault or issue a bus error. Fixes phpredis#1076
1 parent 336a49b commit 335c058

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

redis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ PHP_REDIS_API int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
799799
#if (PHP_MAJOR_VERSION < 7)
800800
zend_list_delete(Z_LVAL_P(socket));
801801
#else
802-
zend_list_delete(Z_RES_P(socket));
802+
zend_list_close(Z_RES_P(socket));
803803
#endif
804804
}
805805
}

0 commit comments

Comments
 (0)