We assign the moved params[0u] to params, which causes memory leak.
At first, params[0u] holds the object value, and params holds the array one, i.e. params[0u]. After the assigning, params holds the object value exactly, but where is the array value?? params[0u] is just a Json::Value, and we can never retrieve it again. Since the array/object value's value_ field is a map which is allocated by new, the memory leaks.
I think the reason for this problem is that we use the movement version of operator= of Json::Value which is caused by the use of std::move above. After assigning, params[0u] holds the array value, but can never be deconstructed.
In my test, after simply removing the std::move, there is no memory leak anymore.
This was a great catch, @LoveULin. Thank you.
Most helpful comment
This was a great catch, @LoveULin. Thank you.