[MMAPI R28.2] Segmentation Fault at delete NvV4l2Element object after deinitPlane()

I’m thinking about an interim measures for a memory leak issue.
–> Refer: https://devtalk.nvidia.com/default/topic/1035330/jetson-tx2/-mmapi-r28-2-r28-1-deinitplane-of-nvvideoencoder-memory-leak-/

This issue (memory leak) occurs in dynamic resolution changing.

Outline of processing
(1) Stop Device

  • Stop Converter and Encoder (STREAMOFF)
  • De-allocate Buffers
  • Stop Worker Thread (send EOS and waitForDqThread())
    (2) Re-setting and Re-start
  • Configure Converter and Encoder
  • Allocate Buffers
  • Set Callback and Worker Thread
  • Start Converter and Encoder (STREAMON)

I thought that to delete Converter and Encoder objects makes the available memory back.
Then I added a process to the above sequence between (1) and (2):

  • Delete Converter and Encoder

Unfortunately, “Segmentation Fault” error occured in the destructor.

As a result of the analysis, I found an issue in v4l2_ioctl(fd, VIDIOC_REQBUFS, 0) of reqbuf().
When this ioctl called twice, after about 160msec “Segmentation Fault” occurs.
In the second called deinitPlane(),
de-allocation of buffers(data) and NvBuffer are executed normally using a variable of number of buffers.

In the NvV4l2Element destructor, deinitPlane() methods are called.
When the user program calls deinitPlane() and delete object, deinitPlane() is called twice.

Anyone can reproduce this issue easily by calling deinitPlane() twice.

NvV4l2ElementPlane object has number of buffers as variable num_buffers.
If this issue will not be corrected soon, it can be handled easily, I think.
(I have not yet tested it.)



reqbufs(memory_type, 0);


if (num_buffers > 0) reqbufs(memory_type, 0);

Best Regards

I have inserted this code into NvV4l2ElementPlane::deinitPlane().

if (num_buffers == 0) return;

“Segmentation Fault” error has gone away.
It is only a workaround until the permanent fix of v4l2_ioctl().

Best Regards

Hi mynaemi,

Thanks for your info, denitplane will release all dma buf held by fd, then fd will not available.
Free a buffer with invalid fd will lead to unexpected result.

So we should make sure deinitplane been not called twice here.

wayne zhu

Hi waynezhu,

Thanks for your reply.

Will this issue be fixed in the next release ?
Or is this limitation written in any documentation (e.g. Release Note) ?

Best Regards

Hi mynaemi,
I don’t think we will do any changes about this.
We may add a release note to notify this.

APP side should take care of this.

wayne zhu