sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

[mem leakage]Does wrapping the mget inside try ... catch cause memory leakage? #311

Closed UlfbertHuynh closed 2 years ago

UlfbertHuynh commented 2 years ago
RedisCacheDataLoader<V, Formatter>::mget(const std::vector<std::string>& keys) {
   ...
    std::vector<sw::redis::OptionalString> values;
    try{
        redis->mget(keys.begin(), keys.end(), std::back_inserter(values));
    } catch (sw::redis::Error error) {
        LOG(ERROR) << "Error getting data from redis: " << error.what();
        return out;
    }
...

Given the above code will this cause any memory leakage ? I'm worrying inside mget() may Error is thrown before some cleaning up operation.

wingunder commented 2 years ago

Hi @UlfbertHuynh,

It should not leak, but you can easily test it by using Valgrind. There are many on-line tutorials to find out how to use Valgrind, just in case you're not familiar with it.

Regards

sewenew commented 2 years ago

NO, mget doesn't leak memory. The code looks good to me.

Regards