Closed d34d10cc closed 4 years ago
Can you explain more? I don't see how this fixes anything?
Sure. At this line, the code path goes into the OpenSSL/WolfSSL implementations where on this line an internal context is created with an empty options struct. The function goes on to properly use the original options passed in from us_create_socket_context
, but never copies them into the context created with the empty options struct, which it returns to us_create_socket_context
, which in turn returns it immediately, without going on to the next block where the options are properly copied over into the created context in the non-SSL case. This leaves the options alloc'd in deep_str_copy
at the beginning of the function without references, so they don't get cleaned up later in us_socket_context_free
. Everything works properly, but the initial options used to set up the context are leaked.
Multiple ways to fix this, I just chose the one with the least code changes and also to avoid setting e.g. these options two times in the SSL case. The change in us_socket_context_free
is to avoid a double free in the SSL case. (A little bit of a verbose explanation, just following my train of thought :)
Alright I have made some bigger changes that covers this also. It doesn't seem like a memory leak, rather a recursion bug which probably added the context two times in the loop's list. This is fixed now, thanks for reporting & proposing a fix!
SSL options copied with
deep_str_copy
inus_create_socket_context
were not being properly freed (detected with Valgrind), because they were not being properly copied over to the context when SSL was enabled.Relatively minor leaks; nevertheless, good to patch them up.