Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-10-19 16:46:32 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-10-19 16:46:32 +0300
commit75e7c81dad243eda06c332dcd4c5ecfe2e0c4a68 (patch)
tree3f06eca80e66b3e4b8c2acef9ead87810a939bac /redis_array_impl.c
parent621afa6c6d9f0d71a68361e7ae40c75fce1fa382 (diff)
Revert "Refactor ra_extract_key"
This reverts commit 621afa6c6d9f0d71a68361e7ae40c75fce1fa382.
Diffstat (limited to 'redis_array_impl.c')
-rw-r--r--redis_array_impl.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 4a60fdde..1a5aa7ba 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -401,7 +401,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
if (Z_TYPE(z_ret) == IS_STRING) {
*out_len = Z_STRLEN(z_ret);
- out = Z_STRVAL(z_ret);
+ out = estrndup(Z_STRVAL(z_ret), *out_len);
}
zval_dtor(&z_argv);
@@ -418,11 +418,11 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS
if (Z_TYPE(ra->z_fun) != IS_NULL) {
return ra_call_extractor(ra, key, key_len, out_len TSRMLS_CC);
} else if ((start = strchr(key, '{')) == NULL || (end = strchr(start + 1, '}')) == NULL) {
- return (char *)key;
+ return estrndup(key, key_len);
}
/* found substring */
*out_len = end - start - 1;
- return start + 1;
+ return estrndup(start + 1, *out_len);
}
/* call userland key distributor function */
@@ -461,13 +461,13 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
int pos, out_len;
/* extract relevant part of the key */
- if ((out = ra_extract_key(ra, key, key_len, &out_len TSRMLS_CC)) == NULL) {
- return NULL;
- }
+ out = ra_extract_key(ra, key, key_len, &out_len TSRMLS_CC);
+ if(!out) return NULL;
if (Z_TYPE(ra->z_dist) != IS_NULL) {
pos = ra_call_distributor(ra, key, key_len TSRMLS_CC);
if (pos < 0 || pos >= ra->count) {
+ efree(out);
return NULL;
}
} else {
@@ -483,6 +483,7 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
/* get position on ring */
pos = (int)(hash * ra->count / 0xffffffff);
}
+ efree(out);
if(out_pos) *out_pos = pos;