NVENC memory leak bug


Using NV_ENC_PRESET_P6_GUID (and P7) results in memory leak. P5 and below does not result in leak. To reproduce compile and run the gist below.

The size of the leak correlates with params.encodeWidth and params.encodeHeight.

This results in unstable implementations when repeatedly running encoding jobs within the same process.

gpu: Nvidia Tesla T4
os: Ubuntu 20.04.1 LTS
nvidia version: 450.80.02 (455.45.01 also tested)
cuda version: 11.0.221
reproduce: https://gist.github.com/fredrikwidlund/eaec7efb6df21beb5914321df28d8e71

Kind regards,
Fredrik Widlund


Hi Fredrik,
Which command you used to observe the memory leak?
We will try to reproduce this issue internally. For future reference, this is being tracked as 200684132.

Hi Mandar,

Either run valgrind --leak-check=full ./main which should give something similar to
==3150456== 32 bytes in 1 blocks are definitely lost in loss record 12 of 82
==3150456== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==3150456== by 0x661F49D: ???
==3150456== by 0x661E808: ???
==3150456== by 0x660D3F1: ???
==3150456== by 0x661B45B: ???
==3150456== by 0x10931E: encode (a.c:21)
(being: e = nvenc->nvEncOpenEncodeSessionEx(&session_params, &encoder);)
==3150456== by 0x10972D: main (a.c:70)
[… ignore cuda …]
==3150456== 6,952 bytes in 1 blocks are definitely lost in loss record 77 of 82
==3150456== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==3150456== by 0x68C5E94: ???
==3150456== by 0x68DD4C2: ???
==3150456== by 0x68BE367: ???
==3150456== by 0x661292E: ???
==3150456== by 0x660D609: ???
==3150456== by 0x661D168: ???
==3150456== by 0x10951A: encode (a.c:40)
(being: e = nvenc->nvEncInitializeEncoder(encoder, &params);)
==3150456== by 0x10972D: main (a.c:70)

or uncomment row 70 (while(1)) and watch the process with ps or similar to see it grow continuously. Change to NV_ENC_PRESET_P5_GUID to see the problem go away.

This is also by customer care being tracked as: Bug 3200651 - NVENC bug [Incident: 201123-000219]

Kind regards,