Memory leak information is observed in case nveglglessink plugin is used

I run below command on AGX platform, the memory leak information could be observed in the log for each pipeline.

GST_DEBUG="*:7,GST_TRACER:7" GST_TRACERS=“leaks” GST_DEBUG_FILE=~/eglessinkleaks.txt gst-launch-1.0 -e v4l2src device=/dev/video0 ! capsfilter name=capsfilter0 caps=“video/x-raw,format=(string)UYVY,width=1920,height=1080,framerate=30/1” ! nvvidconv name=nvvidconvt00 ! nvegltransform name=nvegltransform0 ! nveglglessink name=nveglglessink0 create-window=true sync=false

leak information from GST_TRACER is listed below.
GST_TRACER :0::e[00m object-alive, type-name=(string)GstEGLImageAllocator, address=(gpointer)0x5594fcad50, description=(string), ref-count=(uint)2, tr
GST_TRACER :0::e[00m object-alive, type-name=(string)GstEglGlesSink, address=(gpointer)0x5594fc39e0, description=(string), ref-count=(uint)1, trace=(strin
GST_TRACER :0::e[00m object-alive, type-name=(string)GstPad, address=(gpointer)0x5594f5b180, description=(string)nveglglessink0:sink, ref-count=(uint)1, trace=(string);

Would you please help us whether memory leak issue is existed in nveglglessink.
Thanks.

Hi,
Thanks for reporting it. We will check and update.

nveglglessink is open source, would be great if you can download it and do further check. This will be very helpful.

Please check the patch in this comment

The nveglglessink plugin is open source. Please apply this patch to rebuild the plugin and try again:

diff --git a/ext/eglgles/gstegladaptation.c b/ext/eglgles/gstegladaptation.c
index 2498467..1cb25e4 100644
--- a/ext/eglgles/gstegladaptation.c
+++ b/ext/eglgles/gstegladaptation.c
@@ -690,7 +690,8 @@ void
 gst_egl_adaptation_context_free (GstEglAdaptationContext * ctx)
 {
   gst_egl_adaptation_deinit (ctx);
-  gst_object_unref (ctx->element);
+  if (GST_OBJECT_REFCOUNT(ctx->element))
+    gst_object_unref (ctx->element);
   g_free (ctx);
 }
 
diff --git a/ext/eglgles/gsteglglessink.c b/ext/eglgles/gsteglglessink.c
index f5811a4..f31a5e5 100644
--- a/ext/eglgles/gsteglglessink.c
+++ b/ext/eglgles/gsteglglessink.c
@@ -382,8 +382,6 @@ gst_egl_image_buffer_pool_set_config (GstBufferPool * bpool,
   if (!gst_buffer_pool_config_get_allocator (config, &pool->allocator,
           &pool->params))
     return FALSE;
-  if (pool->allocator)
-    gst_object_ref (pool->allocator);
 
   pool->add_metavideo =
       gst_buffer_pool_config_has_option (config,
@@ -2884,7 +2882,8 @@ gst_eglglessink_close (GstEglGlesSink * eglglessink)
     }
   }
 #endif
-
+  if (GST_OBJECT_REFCOUNT(eglglessink))
+    gst_object_unref (eglglessink);
   return TRUE;
 }

Hi Danel,

We are now facing that compiling the nveglglessink module goes wrong.
We have execute this follow cmd as README.txt

  1. Untar the package and enter the dir
  2. ./autogen.sh
  3. ./configure
  4. make ----issue
  5. sudo make install

error log as follow :
gsteglglessink.c:99:10: fatal error: nvbufsurface.h: No such file or directory
#include “nvbufsurface.h”

When copy the nvbufsurface.h and other head file to current dir , there has another compiler error.

…/…/cudaGL.h:167:1: error: unknown type name ‘CUresult’
CUresult CUDAAPI cuGraphicsGLRegisterBuffer(CUgraphicsResource *pCudaResource, GLuint buffer, unsigned int Flags);
^~~~~~~~
…/…/cudaGL.h:167:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘cuGraphicsGLRegisterBuffer’
CUresult CUDAAPI cuGraphicsGLRegisterBuffer(CUgraphicsResource *pCudaResource, GLuint buffer, unsigned int Flags);

Could you please help on this?
thanks

Hi,
Please copy attached Makefile to

gstegl_src/gst-egl/Makefile.public

And execute the steps:

gstegl_src/gst-egl$ ./configure
gstegl_src/gst-egl$ cp Makefile.public Makefile
gstegl_src/gst-egl$ CUDA_VER=10.2 make

And then replace libgstnveglglessink.so:

gstegl_src/gst-egl$ sudo cp libgstnveglglessink.so /usr/lib/aarch64-linux-gnu/gstreamer-1.0/

gstegl_TEST_Makefile.zip (1.1 KB)

Please backup original file before the replacement.

hi DaneLLL
we has solve the complier issue using the attached Makefile.
we apply the patch to rebuild the plugin and try again.
But when pipeline running, it only executes normal once .
The second time running, there has some log as follow:
GLib-GObject-CRITICAL **: 17:31:30.889: g_object_ref: assertion ‘G_IS_OBJECT (object)’ failed
GStreamer-CRITICAL **: 17:31:30.889: gst_object_unref: assertion ‘object != NULL’ failed.
maybe I merge the patch with some mistake.
can you help me check the code or give me the gstegl_src.tbz2 file.

ths!
gstegladaptation.c (21.4 KB)
gsteglglessink.c (109.1 KB)

Hi,
Please try this patch:

diff --git a/ext/eglgles/gstegladaptation.c b/ext/eglgles/gstegladaptation.c
index 2498467..1cb25e4 100644
--- a/ext/eglgles/gstegladaptation.c
+++ b/ext/eglgles/gstegladaptation.c
@@ -690,7 +690,8 @@ void
 gst_egl_adaptation_context_free (GstEglAdaptationContext * ctx)
 {
   gst_egl_adaptation_deinit (ctx);
-  gst_object_unref (ctx->element);
+  if (GST_OBJECT_REFCOUNT(ctx->element))
+    gst_object_unref (ctx->element);
   g_free (ctx);
 }
 
diff --git a/ext/eglgles/gsteglglessink.c b/ext/eglgles/gsteglglessink.c
index f5811a4..b41c963 100644
--- a/ext/eglgles/gsteglglessink.c
+++ b/ext/eglgles/gsteglglessink.c
@@ -382,8 +382,6 @@ gst_egl_image_buffer_pool_set_config (GstBufferPool * bpool,
   if (!gst_buffer_pool_config_get_allocator (config, &pool->allocator,
           &pool->params))
     return FALSE;
-  if (pool->allocator)
-    gst_object_ref (pool->allocator);
 
   pool->add_metavideo =
       gst_buffer_pool_config_has_option (config,
@@ -2471,8 +2469,10 @@ gst_eglglessink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
   /* First the default allocator */
   if (!gst_egl_image_memory_is_mappable ()) {
     allocator = gst_allocator_find (NULL);
-    gst_query_add_allocation_param (query, allocator, &params);
-    gst_object_unref (allocator);
+    if (allocator) {
+      gst_query_add_allocation_param (query, allocator, &params);
+      gst_object_unref (allocator);
+    }
   }
 
   allocator = gst_egl_image_allocator_obtain ();
@@ -2885,6 +2885,8 @@ gst_eglglessink_close (GstEglGlesSink * eglglessink)
   }
 #endif
 
+  if (GST_OBJECT_REFCOUNT(eglglessink))
+    gst_object_unref (eglglessink);
   return TRUE;
 }
 
diff --git a/gst-libs/gst/egl/egl.c b/gst-libs/gst/egl/egl.c
index d539745..af54ad3 100644
--- a/gst-libs/gst/egl/egl.c
+++ b/gst-libs/gst/egl/egl.c
@@ -269,13 +269,10 @@ gst_egl_image_allocator_init_instance (gpointer data)
 GstAllocator *
 gst_egl_image_allocator_obtain (void)
 {
-  static GOnce once = G_ONCE_INIT;
+  GstAllocator *allocator;
 
-  g_once (&once, gst_egl_image_allocator_init_instance, NULL);
-
-  g_return_val_if_fail (once.retval != NULL, NULL);
-
-  return GST_ALLOCATOR (g_object_ref (once.retval));
+  allocator = gst_egl_image_allocator_init_instance(NULL);
+  return GST_ALLOCATOR (g_object_ref (allocator));
 }
 
 GstMemory *

In default code it initializes allocator into static object. Have to dynamically initialize the object in every launch.

hi DaneLLL
We use the new patch , and solve the issue.
compare the old and new code .
Old code : memory about 40.4M , pipeline start/stop 20 time
New code : memory about 38.4M , pipeline start/stop 20 time
the memleak reduce about 2M .
the new patch is normal ?

Hi,
The patch resolves the leaks reported in GST_TRACER. Should be good. Would suggest set up and run a long run test for further verification.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.