From 0ffc4c3218a2a1ca45405754c86221d295d00dd1 Mon Sep 17 00:00:00 2001 From: Maxim Dounin Date: Mon, 5 Mar 2012 13:17:56 +0000 Subject: Merge of r4498: Fix of rbtree lookup on hash collisions. Previous code incorrectly assumed that nodes with identical keys are linked together. This might not be true after tree rebalance. Patch by Lanshun Zhou. --- src/http/ngx_http_file_cache.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/http/ngx_http_file_cache.c') diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c index 0fe2c4af8..68943a87b 100644 --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -673,21 +673,16 @@ ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key) /* node_key == node->key */ - do { - fcn = (ngx_http_file_cache_node_t *) node; + fcn = (ngx_http_file_cache_node_t *) node; - rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key, - NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); + rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key, + NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); - if (rc == 0) { - return fcn; - } - - node = (rc < 0) ? node->left : node->right; - - } while (node != sentinel && node_key == node->key); + if (rc == 0) { + return fcn; + } - break; + node = (rc < 0) ? node->left : node->right; } /* not found */ -- cgit