comparison src/http/ngx_http_file_cache.c @ 4497:95ab6658654a

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 27 Feb 2012 22:15:39 +0000
parents 41f640a693de
children 9ea42922a395
comparison
equal deleted inserted replaced
4496:be6c250b827b 4497:95ab6658654a
797 continue; 797 continue;
798 } 798 }
799 799
800 /* node_key == node->key */ 800 /* node_key == node->key */
801 801
802 do { 802 fcn = (ngx_http_file_cache_node_t *) node;
803 fcn = (ngx_http_file_cache_node_t *) node; 803
804 804 rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key,
805 rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key, 805 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
806 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); 806
807 807 if (rc == 0) {
808 if (rc == 0) { 808 return fcn;
809 return fcn; 809 }
810 } 810
811 811 node = (rc < 0) ? node->left : node->right;
812 node = (rc < 0) ? node->left : node->right;
813
814 } while (node != sentinel && node_key == node->key);
815
816 break;
817 } 812 }
818 813
819 /* not found */ 814 /* not found */
820 815
821 return NULL; 816 return NULL;