From 75e7c81dad243eda06c332dcd4c5ecfe2e0c4a68 Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Thu, 19 Oct 2017 16:46:32 +0300 Subject: Revert "Refactor ra_extract_key" This reverts commit 621afa6c6d9f0d71a68361e7ae40c75fce1fa382. --- redis_array_impl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'redis_array_impl.c') 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; -- cgit v1.2.3