Unfreed handle

I have an application that uses an NvBuffer and NvEglRenderer to display image data. Everything works as expected but at the end of my application it always prints the message: “NvEglHandle: Unfreed handle upon egl deinit: type=2 refcnt=2”.

Not sure if this means I have a memory leak or forgot to free something? I destroyed all NvBuffers used, so I’m not sure what could be causing this.

Please check if you call below APIs in pair for each NvBuffer:

/**
* This method must be used for getting `EGLImage` from `dmabuf-fd`.
*
* @param[in] display `EGLDisplay` object used during the creation of `EGLImage`.
* @param[in] dmabuf_fd `DMABUF FD` of buffer from which `EGLImage` to be created.
*
* @returns `EGLImageKHR` for success, `NULL` for failure
*/
EGLImageKHR NvEGLImageFromFd (EGLDisplay display, int dmabuf_fd);

/**
* This method must be used for destroying `EGLImage` object.

* @param[in] display `EGLDisplay` object used for destroying `EGLImage`.
* @param[in] eglImage `EGLImageKHR` object to be destroyed.
*
* @returns 0 for success, -1 for failure
*/
int NvDestroyEGLImage (EGLDisplay display, EGLImageKHR eglImage);
/**
* This method must be used for getting mem mapped virtual Address of the plane.
* @param[in] dmabuf_fd DMABUF FD of buffer.
* @param[in] plane video frame plane.(Applicale for NvBufferPayload_SurfArray)
* @param[in] memflag NvBuffer memory flag.
* @param[in] pVirtAddr Virtual Addres pointer of the mem mapped plane.
*
* @returns 0 for success, -1 for failure.
*/
int NvBufferMemMap (int dmabuf_fd, unsigned int plane, NvBufferMemFlags memflag, void **pVirtAddr);

/**
* This method must be used to Unmap the mapped virtual Address of the plane.
* @param[in] dmabuf_fd DMABUF FD of buffer.
* @param[in] plane video frame plane.(Applicale for NvBufferPayload_SurfArray)
* @param[in] pVirtAddr mem mapped Virtual Addres pointer of the plane.
*
* @returns 0 for success, -1 for failure.
*/
int NvBufferMemUnMap (int dmabuf_fd, unsigned int plane, void **pVirtAddr);

Certain APIs in nvbuf_utils.h have to be called in pair. Please take a look at the header file.

I have called the following pairs but still get the same message:

  1. NvBufferCreateEx (int *dmabuf_fd, NvBufferCreateParams *input_params) in pair with int NvBufferDestroy (int dmabuf_fd)
  2. NvBufferMemMap (int dmabuf_fd, unsigned int plane, NvBufferMemFlags memflag, void **pVirtAddr) with NvBufferMemUnMap (int dmabuf_fd, unsigned int plane, void **pVirtAddr)

I also call Raw2NvBuffer, but this is in relation to the NvBuffer I call NvBufferDestroy on.

I think it has to do with the NvEglRenderer, but I don’t see an appropriate function to call in NvEglRenderer other than render().

Hi,
Please share us a simple test app to reproduce the issue. Thanks.