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

Skip to content

Commit 91bd742

Browse files
Masters info leakfix (#1462)
Fix for memory leaks in `RedisCluster->_masters()` and `RedisCluster->info()`
1 parent 9d1bdb7 commit 91bd742

4 files changed

Lines changed: 44 additions & 36 deletions

File tree

cluster_library.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,12 +2072,13 @@ PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
20722072
}
20732073

20742074
/* Parse response, free memory */
2075+
REDIS_MAKE_STD_ZVAL(z_result);
20752076
redis_parse_info_response(info, z_result);
20762077
efree(info);
20772078

20782079
// Return our array
20792080
if (CLUSTER_IS_ATOMIC(c)) {
2080-
RETVAL_ZVAL(z_result, 1, 0);
2081+
RETVAL_ZVAL(z_result, 0, 1);
20812082
} else {
20822083
add_next_index_zval(&c->multi_resp, z_result);
20832084
}

library.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ PHP_REDIS_API void redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
840840
}
841841

842842
/* Parse it into a zval array */
843+
REDIS_MAKE_STD_ZVAL(z_ret);
843844
redis_parse_info_response(response, z_ret);
844845

845846
/* Free source response */

redis_cluster.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,25 +2026,21 @@ PHP_METHOD(RedisCluster, _unserialize) {
20262026
PHP_METHOD(RedisCluster, _masters) {
20272027
redisCluster *c = GET_CONTEXT();
20282028
redisClusterNode *node;
2029-
zval zv, *z_ret = &zv;
20302029

2031-
array_init(z_ret);
2030+
array_init(return_value);
20322031

20332032
ZEND_HASH_FOREACH_PTR(c->nodes, node) {
20342033
if (node == NULL) break;
20352034

20362035
zval z, *z_sub = &z;
2037-
#if (PHP_MAJOR_VERSION < 7)
2038-
MAKE_STD_ZVAL(z_sub);
2039-
#endif
2036+
2037+
REDIS_MAKE_STD_ZVAL(z_sub);
20402038
array_init(z_sub);
20412039

20422040
add_next_index_stringl(z_sub, ZSTR_VAL(node->sock->host), ZSTR_LEN(node->sock->host));
20432041
add_next_index_long(z_sub, node->sock->port);
2044-
add_next_index_zval(z_ret, z_sub);
2042+
add_next_index_zval(return_value, z_sub);
20452043
} ZEND_HASH_FOREACH_END();
2046-
2047-
RETVAL_ZVAL(z_ret, 1, 0);
20482044
}
20492045

20502046
PHP_METHOD(RedisCluster, _redir) {
@@ -2714,6 +2710,7 @@ PHP_METHOD(RedisCluster, info) {
27142710
int cmd_len;
27152711
strlen_t opt_len = 0;
27162712
void *ctx = NULL;
2713+
27172714
zval *z_arg;
27182715
short slot;
27192716

tests/RedisTest.php

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,36 +1882,45 @@ public function testWait() {
18821882
}
18831883

18841884
public function testInfo() {
1885-
$info = $this->redis->info();
1885+
foreach (Array(false, true) as $boo_multi) {
1886+
if ($boo_multi) {
1887+
$this->redis->multi();
1888+
$this->redis->info();
1889+
$info = $this->redis->exec();
1890+
$info = $info[0];
1891+
} else {
1892+
$info = $this->redis->info();
1893+
}
18861894

1887-
$keys = array(
1888-
"redis_version",
1889-
"arch_bits",
1890-
"uptime_in_seconds",
1891-
"uptime_in_days",
1892-
"connected_clients",
1893-
"connected_slaves",
1894-
"used_memory",
1895-
"total_connections_received",
1896-
"total_commands_processed",
1897-
"role"
1898-
);
1899-
if (version_compare($this->version, "2.5.0", "lt")) {
1900-
array_push($keys,
1901-
"changes_since_last_save",
1902-
"bgsave_in_progress",
1903-
"last_save_time"
1895+
$keys = array(
1896+
"redis_version",
1897+
"arch_bits",
1898+
"uptime_in_seconds",
1899+
"uptime_in_days",
1900+
"connected_clients",
1901+
"connected_slaves",
1902+
"used_memory",
1903+
"total_connections_received",
1904+
"total_commands_processed",
1905+
"role"
19041906
);
1905-
} else {
1906-
array_push($keys,
1907-
"rdb_changes_since_last_save",
1908-
"rdb_bgsave_in_progress",
1909-
"rdb_last_save_time"
1910-
);
1911-
}
1907+
if (version_compare($this->version, "2.5.0", "lt")) {
1908+
array_push($keys,
1909+
"changes_since_last_save",
1910+
"bgsave_in_progress",
1911+
"last_save_time"
1912+
);
1913+
} else {
1914+
array_push($keys,
1915+
"rdb_changes_since_last_save",
1916+
"rdb_bgsave_in_progress",
1917+
"rdb_last_save_time"
1918+
);
1919+
}
19121920

1913-
foreach($keys as $k) {
1914-
$this->assertTrue(in_array($k, array_keys($info)));
1921+
foreach($keys as $k) {
1922+
$this->assertTrue(in_array($k, array_keys($info)));
1923+
}
19151924
}
19161925
}
19171926

0 commit comments

Comments
 (0)