From 6065f276c4437036ce7455cbb2177fdce1f2c450 Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 2 Mar 2021 01:38:12 +0000 Subject: [PATCH] Key prefetch error handling instead of crashign Former-commit-id: b322a14efb1b897134b229c1726b45264b57783f --- src/db.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 20e8ac014..9d05e8082 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -2970,6 +2970,8 @@ void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command lock.arm(c); getKeysResult result = GETKEYS_RESULT_INIT; auto cmd = lookupCommand(szFromObj(command.argv[0])); + if (cmd == nullptr) + return; // Bad command? It's not for us to judge, just bail int numkeys = getKeysFromCommand(cmd, command.argv, command.argc, &result); for (int ikey = 0; ikey < numkeys; ++ikey) { @@ -2994,10 +2996,14 @@ void redisDbPersistentData::prefetchKeysAsync(client *c, parsed_command &command serverAssert(o != nullptr); }, &sharedKey); - if (sharedKey == nullptr) - sharedKey = sdsdupshared(szFromObj(objKey)); + if (o != nullptr) { + if (sharedKey == nullptr) + sharedKey = sdsdupshared(szFromObj(objKey)); - vecInserts.emplace_back(sharedKey, o, std::move(spexpire)); + vecInserts.emplace_back(sharedKey, o, std::move(spexpire)); + } else if (sharedKey != nullptr) { + sdsfree(sharedKey); + } } lock.arm(c);