Memory leak in nvEncOpenEncodeSessionEx

Hi,

We found some small memory leak within nvEncOpenEncodeSessionEx by Valgrind.
See log:

==12787== 32 bytes in 1 blocks are still reachable in loss record 13 of 83
==12787== at 0x4C2C857: malloc (vg_replace_malloc.c:291)
==12787== by 0xBC4576D: ??? (in /usr/lib/nvidia-430/libnvidia-encode.so.430.14)
==12787== by 0xBC447F8: ??? (in /usr/lib/nvidia-430/libnvidia-encode.so.430.14)
==12787== by 0xBC2E6B1: ??? (in /usr/lib/nvidia-430/libnvidia-encode.so.430.14)
==12787== by 0xBC3C30B: ??? (in /usr/lib/nvidia-430/libnvidia-encode.so.430.14)

Our code is very simple. We just call nvEncOpenEncodeSessionEx() in loop until we get zero session handle, then call nvEncDestroyEncoder() for all valid instances obtained in loop. We use this code to understand how much NVEnc sessions we can run simultaneously. It looks like the last call of nvEncOpenEncodeSessionEx() which returned zero handle produces this memory leak.

It would be nice if someone looked at it and confirmed the bug or found that it was a false positive detection of Valgrind.

Thanks in advance!

I also had a memory leak in my implementation until I figured out that I had to destroy the context.
DestroyEncoder() is called by the destructor
Where -> ReleaseInputBuffers();
and -> DestroyHWEncoder();
are called…

Everything should be gone now… but looking at the nvidia-smi tool you see memory still occupied and the(my) process listed as still claiming resources.

This might not be your exact problem but I thought I mention it anyway. I solved it like this->

my nvEnc declaration ->

std::unique_ptr<NvEncoderCuda> nvEnc = nullptr;

Then to stop and release the resources->

void EncoderWrapper::stopEncoder() {
    nvEnc = nullptr;
    CUresult res = cuCtxDestroy(cuContext);
    LOGGER(false, LOGG_FATAL, "cuCtxDestroy: " << res);
}