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

Skip to content

Commit c76e00f

Browse files
committed
Fix memory leak on PHP 5
1 parent a370382 commit c76e00f

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

library.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,15 +1894,11 @@ redis_sock_disconnect(RedisSock *redis_sock, int force TSRMLS_DC)
18941894
zend_string *persistent_id = strpprintf(0, "phpredis_%s:%d", ZSTR_VAL(redis_sock->host), redis_sock->port);
18951895
zend_resource *le = zend_hash_find_ptr(&EG(persistent_list), persistent_id);
18961896
if (!le) {
1897-
#if (PHP_MAJOR_VERSION < 7)
1898-
le = ecalloc(1, sizeof(*le));
1899-
#else
1900-
zend_resource res;
1901-
le = &res;
1902-
#endif
1897+
zend_llist *l = pecalloc(1, sizeof(*l) + sizeof(*le), 1);
1898+
zend_llist_init(l, sizeof(void *), NULL, 1);
1899+
le = (void *)l + sizeof(*l);
19031900
le->type = le_redis_pconnect;
1904-
le->ptr = pecalloc(1, sizeof(zend_llist), 1);
1905-
zend_llist_init(le->ptr, sizeof(void *), NULL, 1);
1901+
le->ptr = l;
19061902
zend_hash_str_update_mem(&EG(persistent_list), ZSTR_VAL(persistent_id), ZSTR_LEN(persistent_id), le, sizeof(*le));
19071903
}
19081904
zend_llist_prepend_element(le->ptr, &redis_sock->stream);

0 commit comments

Comments
 (0)