amazon-kinesis-video-streams-producer-sdk-cpp icon indicating copy to clipboard operation
amazon-kinesis-video-streams-producer-sdk-cpp copied to clipboard

Fix memory leak in failed DefaultCallbackProvider constructor

Open grantralston opened this issue 1 year ago • 0 comments

Description of changes:

I noticed a leak in memory in our application and was able to trace it to the KVS C++ Producer Library. This situation was mainly occuring when the producer could not reach the internet.

Our application is long-living, and will restart the pipeline with kvssink if it fails very quickly, so in times of internet outage we cycle through instances of kvssink fairly quickly.

img

As is visible in the graph, at the time this dump was taken, KVS Producer was responsible for 30GB of memory coming from createCurlApiCallbacks. On investigation, I was able trace this back to the DefaultCallbackProvider not freeing memory allocated to PClientCallbacks instance when the constructor failed.

This issue was fixed by transitioning the PClientCallbacks instance to a separate RAII instance that will automatically free when the DefaultCallbackProvider instance goes out of scope.

This change has been running in a test environment with the triggering conditions for 4 days and we have seen the leak resolved.

Screenshot 2024-08-05 at 5 25 59 PM

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

grantralston avatar Aug 05 '24 21:08 grantralston