Rippled: processRequest in class ServerHandlerImp may cause memory leak

Created on 6 Jun 2018  路  1Comment  路  Source: ripple/rippled

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.

https://github.com/ripple/rippled/blob/fd4636b0560900bd040b03004a1efc7ddb8369a0/src/ripple/rpc/impl/ServerHandlerImp.cpp#L725

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.

https://github.com/ripple/rippled/blob/fd4636b0560900bd040b03004a1efc7ddb8369a0/src/ripple/json/impl/json_value.cpp#L373

In my test, after simply removing the std::move, there is no memory leak anymore.

Bug

Most helpful comment

This was a great catch, @LoveULin. Thank you.

>All comments

This was a great catch, @LoveULin. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mDuo13 picture mDuo13  路  4Comments

ghost picture ghost  路  3Comments

XieXiaomei-ptr picture XieXiaomei-ptr  路  3Comments

dmitriano picture dmitriano  路  9Comments

ximinez picture ximinez  路  5Comments