diff options
author | antirez <antirez@gmail.com> | 2017-07-20 14:59:42 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2017-07-20 14:59:42 +0200 |
commit | b1c2e1a19c549a49cc124571849976e7ab91d4d1 (patch) | |
tree | f9cf41e73e2c27316b95022b8598d05b0690bb79 | |
parent | b80e467023aa6c882639426b9a2ac691fbc220be (diff) | |
download | redis-b1c2e1a19c549a49cc124571849976e7ab91d4d1.tar.gz |
Fix two bugs in moduleTypeLookupModuleByID().
The function cache was not working at all, and the function returned
wrong values if there where two or more modules exporting native data
types.
See issue #4131 for more details.
-rw-r--r-- | src/module.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/module.c b/src/module.c index 342612a1b..cfa5ea4f7 100644 --- a/src/module.c +++ b/src/module.c @@ -2680,7 +2680,7 @@ moduleType *moduleTypeLookupModuleByID(uint64_t id) { /* Search in cache to start. */ int j; - for (j = 0; j < MODULE_LOOKUP_CACHE_SIZE; j++) + for (j = 0; j < MODULE_LOOKUP_CACHE_SIZE && cache[j].mt != NULL; j++) if (cache[j].id == id) return cache[j].mt; /* Slow module by module lookup. */ @@ -2688,17 +2688,20 @@ moduleType *moduleTypeLookupModuleByID(uint64_t id) { dictIterator *di = dictGetIterator(modules); dictEntry *de; - while ((de = dictNext(di)) != NULL) { + while ((de = dictNext(di)) != NULL && mt == NULL) { struct RedisModule *module = dictGetVal(de); listIter li; listNode *ln; listRewind(module->types,&li); while((ln = listNext(&li))) { - mt = ln->value; + moduleType *this_mt = ln->value; /* Compare only the 54 bit module identifier and not the * encoding version. */ - if (mt->id >> 10 == id >> 10) break; + if (this_mt->id >> 10 == id >> 10) { + mt = this_mt; + break; + } } } dictReleaseIterator(di); |