0xsky / xredis

Redis C++ client, support the data slice storage, support redis cluster, thread-safe,multi-platform,connection pool, read/write separation.
GNU General Public License v3.0
337 stars 153 forks source link

xRedisClusterClient::RedisCommandArgv接口内 FreeReply(reply) 和 RedisResult &result的析构函数导致二次释放崩溃 #43

Closed bulingma closed 5 years ago

bulingma commented 5 years ago

bool xRedisClusterClient::RedisCommandArgv(const VSTRING& vDataIn, RedisResult &result) 函数通过 RedisResult &result 参数将函数执行结果赋值给 result带出,当 FreeReply(reply); 执行后,result 中的结果则已被释放,无有效结果输出;且 RedisResult 的析构函数因为二次释放会导致崩溃。注释掉FreeReply(reply)可解决该问题:修改后代码如下:

bool xRedisClusterClient::RedisCommandArgv(const VSTRING& vDataIn, RedisResult &result){ bool bRet = false; const std::string &key = vDataIn[1]; RedisConnection *pRedisConn = FindNodeConnection(key.c_str()); if (NULL == pRedisConn) { return false; }

vector<const char*> argv(vDataIn.size());
vector<size_t> argvlen(vDataIn.size());
unsigned int j = 0;
for (VSTRING::const_iterator i = vDataIn.begin(); i != vDataIn.end(); ++i, ++j) {
    argv[j] = i->c_str(), argvlen[j] = i->size();
}

redisReply *reply = static_cast<redisReply *>(redisCommandArgv(pRedisConn->mCtx, argv.size(), &(argv[0]), &(argvlen[0])));
if (xRedisClusterClient::CheckReply(reply)) {
    result.Init(reply);
    //printf("%d %lld %d %s %lu \r\n",reply->type, reply->integer, reply->len, reply->str, reply->elements);
    bRet = true;
} else {
    //SetErrInfo(dbi, reply);
}

// FreeReply(reply);

FreeConnection(pRedisConn);
return bRet;

}

0xsky commented 5 years ago

good

0xsky commented 5 years ago

have fixed