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

Skip to content

Commit 0879770

Browse files
committed
Issue #1746
1 parent 37bd504 commit 0879770

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

library.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,8 +2527,9 @@ redis_sock_disconnect(RedisSock *redis_sock, int force)
25272527
if (INI_INT("redis.pconnect.pooling_enabled")) {
25282528
p = redis_sock_get_connection_pool(redis_sock);
25292529
}
2530-
if (force) {
2530+
if (force || !IS_ATOMIC(redis_sock)) {
25312531
php_stream_pclose(redis_sock->stream);
2532+
free_reply_callbacks(redis_sock);
25322533
if (p) p->nb_active--;
25332534
} else if (p) {
25342535
zend_llist_prepend_element(&p->list, &redis_sock->stream);
@@ -2876,6 +2877,19 @@ redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz)
28762877
return -1;
28772878
}
28782879

2880+
void
2881+
free_reply_callbacks(RedisSock *redis_sock)
2882+
{
2883+
fold_item *fi;
2884+
2885+
while (redis_sock->head != NULL) {
2886+
fi = redis_sock->head->next;
2887+
free(redis_sock->head);
2888+
redis_sock->head = fi;
2889+
}
2890+
redis_sock->current = NULL;
2891+
}
2892+
28792893
/**
28802894
* redis_free_socket
28812895
*/
@@ -2897,6 +2911,7 @@ PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock)
28972911
zend_string_release(redis_sock->host);
28982912
}
28992913
redis_sock_free_auth(redis_sock);
2914+
free_reply_callbacks(redis_sock);
29002915
efree(redis_sock);
29012916
}
29022917

library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838

3939
void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id);
40+
void free_reply_callbacks(RedisSock *redis_sock);
4041

4142
PHP_REDIS_API int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass);
4243

redis.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,6 @@ redis_send_discard(RedisSock *redis_sock)
188188
return result;
189189
}
190190

191-
static void
192-
free_reply_callbacks(RedisSock *redis_sock)
193-
{
194-
fold_item *fi;
195-
196-
for (fi = redis_sock->head; fi; ) {
197-
fold_item *fi_next = fi->next;
198-
free(fi);
199-
fi = fi_next;
200-
}
201-
redis_sock->head = NULL;
202-
redis_sock->current = NULL;
203-
}
204-
205191
/* Passthru for destroying cluster cache */
206192
static void cluster_cache_dtor(zend_resource *rsrc) {
207193
if (rsrc->ptr) {
@@ -2228,7 +2214,6 @@ PHP_METHOD(Redis, multi)
22282214

22292215
/* Enable PIPELINE if we're not already in one */
22302216
if (IS_ATOMIC(redis_sock)) {
2231-
free_reply_callbacks(redis_sock);
22322217
REDIS_ENABLE_MODE(redis_sock, PIPELINE);
22332218
}
22342219
} else if (multi_value == MULTI) {
@@ -2467,7 +2452,6 @@ PHP_METHOD(Redis, pipeline)
24672452
/* NB : we keep the function fold, to detect the last function.
24682453
* We need the response format of the n - 1 command. So, we can delete
24692454
* when n > 2, the { 1 .. n - 2} commands */
2470-
free_reply_callbacks(redis_sock);
24712455
REDIS_ENABLE_MODE(redis_sock, PIPELINE);
24722456
}
24732457

0 commit comments

Comments
 (0)