smuehlst / circle-stdlib

Standard C and C++ Library Support for Circle
GNU General Public License v3.0
90 stars 17 forks source link

Memory leaks found by static analysis tool #11

Closed smuehlst closed 4 years ago

smuehlst commented 4 years ago

Leaking memory. CAdaptedSocket [:28] is allocated on the heap and never freed. In function mbedtls_net_connect [:21] .

https://github.com/smuehlst/circle-stdlib/blob/0d349f6a4ffd08f3beae65d8385f461b3cb67029/src/circle-mbedtls/net_sockets.cpp#L28

Leaking memory. CAdaptedSocket [:53] is allocated on the heap and never freed. In function mbedtls_net_bind [:41] .

https://github.com/smuehlst/circle-stdlib/blob/0d349f6a4ffd08f3beae65d8385f461b3cb67029/src/circle-mbedtls/net_sockets.cpp#L53

rsta2 commented 4 years ago

I may look like, that memory is leaked here, because the pointer to pSocket is saved in a static array in CAdaptedSocket and retrieved from there by a handle, which is probably not obvious. It is deleted here:

https://github.com/smuehlst/circle-stdlib/blob/0d349f6a4ffd08f3beae65d8385f461b3cb67029/src/circle-mbedtls/net_sockets.cpp#L169

So I suppose, there is no memory leak here.

smuehlst commented 4 years ago

I see, a very sophisticated example how to outsmart static code analysis :+1: