I need to help about memory leak from custom plugin (DS 4.0)

Hi

I use DS 4.0 on jetson nano dev kit

i made a plugin for draw menu based on dsexample plugin

some changing ,

original(dsexample) - transform_ip ()
new plugin(menudraw) - prepareoutputbuffer -> transform()

  1. my plugin loads some image and convert to Mat
  2. store them in a Mat array (cv::Mat) (init)
  3. menudraw_start
  4. run prepare_output_buffer when source(two camera sources, batchsize = 2, after infer) is input
  5. make a new buffer(batchsize = 1) for outbuf
  6. Set the drawParam using property of the menudraw(page-num, cusor-pos, command)
  7. draw the buffer using DrawParam
  8. In camera setting menu, the input source is composited on the screen (plan to make)

my plugin looks good
but it has 3mb memory leak every sec

If bypass, memory leakage does not occur.

i think, there seems to be a problem during buffer making and using Mat.

i upload my all code of my plugin source

please help me…

Maybe there is a problem with these functions
gst_menudraw_prepare_output_buffer

gst_menudraw_prepare_output_buffer(GstBaseTransform * btrans, GstBuffer * inbuf, GstBuffer ** outbuf)
{
	GstMenuDraw *menudraw = GST_MENUDRAW (btrans);
	GstFlowReturn flow_ret = GST_FLOW_ERROR;	
	GstMapInfo out_map_info;		
	DrawParam DrawParam;
	NvBufSurface *outsurface = NULL;
	NvBufSurfaceCreateParams create_params;
	NvDsBatchMeta *batch_meta = NULL;
	NvDsFrameMeta *frame_meta = NULL;
	NvDsMeta *meta = NULL;
   		
	g_print ("Prepare start\n");	
	//*outbuf = inbuf;
	//return GST_FLOW_OK;
	
	
	if (menudraw->inter_buf)
		NvBufSurfaceDestroy (menudraw->inter_buf);
	menudraw->inter_buf = NULL;	

	/* An intermediate buffer for NV12/RGBA to BGR conversion  will be
	* required. Can be skipped if custom algorithm can work directly on NV12/RGBA. */      
	create_params.gpuId  = menudraw->gpu_id;
	create_params.width  = menudraw->processing_width;
	create_params.height = menudraw->processing_height;
	create_params.size = 0;
	create_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
	create_params.layout = NVBUF_LAYOUT_PITCH;
	#ifdef __aarch64__
	create_params.memType = NVBUF_MEM_DEFAULT;
	g_print("set surface memtype nvbuf_mem_dafault\n");
	#else
	create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
	#endif
	//Make GST Buffer
	if (NvBufSurfaceCreate (&(menudraw->inter_buf), 1,
		  &create_params) != 0) {
	GST_ERROR ("Error: Could not allocate internal buffer for menudraw");
	goto error;
	}
	menudraw->inter_buf->numFilled = 1;
			
	/* An intermediate buffer for NV12/RGBA to BGR conversion  will be
	* required. Can be skipped if custom algorithm can work directly on NV12/RGBA. */      
	/*create_params.gpuId  = menudraw->gpu_id;
	create_params.width  = menudraw->processing_width;
	create_params.height = menudraw->processing_height;
	create_params.size = 0;
	create_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
	create_params.layout = NVBUF_LAYOUT_PITCH;
	#ifdef __aarch64__
	create_params.memType = NVBUF_MEM_DEFAULT;
	g_print("set surface memtype nvbuf_mem_dafault\n");
	#else
	create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
	#endif
	//Make GST Buffer
	if (NvBufSurfaceCreate (&newoutsurface, 1,
		  &create_params) != 0) {
	GST_ERROR ("Error: Could not allocate internal buffer for menudraw");
	goto error;
	}
	newoutsurface->numFilled = 1;*/		
	*outbuf = NULL;
	*outbuf = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_ZERO_PREFIXED, menudraw->inter_buf, sizeof(NvBufSurface), 0, sizeof(NvBufSurface), NULL, NULL);    	
	batch_meta = nvds_create_batch_meta(1);    	
	meta = gst_buffer_add_nvds_meta (*outbuf , batch_meta, NULL, copy_user_meta, release_user_meta);    	
	meta->meta_type = NVDS_BATCH_GST_META;
	batch_meta->base_meta.batch_meta = batch_meta;
	batch_meta->base_meta.copy_func = copy_user_meta;
	batch_meta->base_meta.release_func = release_user_meta;
	batch_meta->max_frames_in_batch = 1;
	frame_meta = nvds_acquire_frame_meta_from_pool(batch_meta);
	//g_print("m4\n");
	nvds_add_frame_meta_to_batch(batch_meta, frame_meta);
	//g_print("m5\n");
	// Some important parameters to fill
	frame_meta->pad_index = 0;
	frame_meta->source_id = 0;
	frame_meta->buf_pts = 0;
	frame_meta->ntp_timestamp = 0;
	frame_meta->frame_num = 0;
	frame_meta->batch_id = 0;
	frame_meta->source_frame_width = 1024;
	frame_meta->source_frame_height = 600;
	frame_meta->num_surfaces_per_frame = 1  ;  
	
	
	CHECK_CUDA_STATUS (cudaSetDevice (menudraw->gpu_id),
		"Unable to set cuda device");

memset (&out_map_info, 0, sizeof (out_map_info));
if (!gst_buffer_map (*outbuf, &out_map_info, GST_MAP_READWRITE)) {
 g_print ("Error: Failed to out map gst buffer\n");		
 goto error; 
}	     
outsurface = (NvBufSurface *) out_map_info.data;
GST_DEBUG_OBJECT (menudraw,"Processing Frame Surface %p\n",outsurface);
if (CHECK_NVDS_MEMORY_AND_GPUID (menudraw, outsurface))
{
   g_print ("Error: Check NVDS Memory And Gpu id\n");
goto error;
}
//NvBufSurfaceMemSet(outsurface, 0, 0, 0);	  			

if (NvBufSurfaceMap (outsurface, 0, 0, NVBUF_MAP_READ_WRITE) != 0){	
	g_print("Draw surface map Error\n");
	return GST_FLOW_ERROR;
}
NvBufSurfaceSyncForCpu (outsurface, 0,0);	

DrawParam = Process_Draw_Update_Func[menudraw->page_num](menudraw, inbuf);
Process_Draw_Menu(outsurface, &DrawParam );

NvBufSurfaceSyncForDevice (outsurface, 0,0);	
if (NvBufSurfaceUnMap (outsurface,  0,0)){
	g_print("Draw surface unmap Error\n");
	goto error;
}

	g_print ("Prepare OK\n");
	flow_ret = GST_FLOW_OK;	
error:	
	gst_buffer_unmap (*outbuf, &out_map_info);		
		
	return flow_ret;	
}

Process_Draw_Update_Func,
Function pointer

Process_Draw_Menu

Process_Draw_Menu(NvBufSurface *surface, DrawParam *drawparam)
{  
    cv::Mat screen;
    cv::Mat roi;
	cv::Mat mask;	
	GstFlowReturn flow_ret = GST_FLOW_ERROR;
	
    
	
	//g_print("Draw Start image count = %d\n",drawparam->image_num);
    //Todo Draw Process;
	 screen =
      cv::Mat (surface->surfaceList[0].planeParams.height[0],surface->surfaceList[0].planeParams.width[0],
      CV_8UC4, surface->surfaceList[0].mappedAddr.addr[0],
     surface->surfaceList[0].planeParams.pitch[0]);
	 g_print("mat make ok\n");
	 screen.setTo(cv::Scalar(90,90,90,255));
	 g_print("mat set background ok\n");
	 std::vector<cv::Mat*>::iterator itr_mat; 
	 std::vector<cv::Rect>::iterator itr_Rect; 
	 for(int i = 0 ; i< drawparam->image_num; i++)
	 {		  
		itr_mat = drawparam->imageparams.vec_image.begin() + i;
		itr_Rect = drawparam->imageparams.vec_rect.begin() + i;
		//g_print("mat size %u, %u\n ",itr_mat->cols, itr_mat->rows);
		//g_print("roi rect %u, %u, %u, %u\n ",itr_Rect->x, itr_Rect->y, itr_Rect->width, itr_Rect->height);
		roi = screen(*itr_Rect);
		cv::cvtColor(**itr_mat,mask,cv::COLOR_BGRA2GRAY);
		cv::threshold(mask, mask, 1, 255, cv::THRESH_BINARY );
		//cv::cvtColor (*itr_mat, roi, cv::COLOR_RGBA2BGRA);		
		(*itr_mat)->copyTo(roi,mask);
	 }
	 std::vector<std::string>::iterator itr_text;
	 std::vector<cv::Point>::iterator itr_point; 
	 std::vector<cv::Scalar>::iterator itr_color; 
	 //g_print("Draw Start text count = %d\n",drawparam->text_num);
	 for(int i = 0 ; i< drawparam->text_num; i++)
	 {		 
		 itr_text = drawparam->textparams.vec_text.begin() + i;
		 itr_point = drawparam->textparams.vec_point.begin() + i;
		 itr_color = drawparam->textparams.vec_color.begin() + i;
		 //g_print("string %s\n",(*itr_text).c_str());
		 cv::putText(screen, (*itr_text).c_str(), *itr_point, cv::FONT_ITALIC , 1, *itr_color, 2);
	 }
    
    
    flow_ret = GST_FLOW_OK;
	g_print("Draw Complete\n");
  
error:
  drawparam->imageparams.vec_image.clear();
  drawparam->imageparams.vec_rect.clear();
  drawparam->textparams.vec_text.clear();
  drawparam->textparams.vec_point.clear();
  drawparam->textparams.vec_color.clear();
  return flow_ret;
}

Hi jchcdev,

As you can see from the release note:
https://docs.nvidia.com/metropolis/deepstream/DeepStream_4.0.2_Release_Notes.pdf
Small memory leak observed; fixes in progress.

I will suggest you to move in the DeepSteam SDK 5.0 first.

Hi kayccc

i tried installation , but deepstream5.0 seems to be need to upper ver than TensorRT 7.0ver

i’m using Jetson Nano now

i downloaded the “nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb”

but nano need to arm64.deb

dpkg: error processing archive /home/yih/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb (--unpack):
 package architecture (amd64) does not match system (arm64)
Errors were encountered while processing:

where do i find it ???

Hi jchcdev,

You will need to upgrade your Jetson Nano by JetPack 4.4 DP version to be working with DeepStream DK 5.0.

Thanks

Ok i will do reply after checked DS5.0 migration

thanks !

hi
i migrated DS4.0 to DS5.0 with your recommend
but the memory leak problem has not cleared and got a new problem
(my code changes the drop property of the valve element every time push ‘m’ button for change the screenmode (inference <-> menu)

if(is_menu_mode == TRUE)
{
g_print (“set menu mode”);

     g_object_set(G_OBJECT (valve_infer), "drop", TRUE, NULL);	 		   
     g_object_set(G_OBJECT (valve_menu), "drop", FALSE, NULL);	
     
     
     g_object_set (G_OBJECT (menudraw), "page-num", 0, NULL);
     g_object_set (G_OBJECT (menudraw), "cursor-pos", 0, NULL);
     g_object_set (G_OBJECT (menudraw), "command", 0, NULL);		    		     
 }
 else
 {
     g_print ("set infer mode");		   
     g_object_set(G_OBJECT(valve_menu),"drop",TRUE,NULL);	    
     g_object_set(G_OBJECT(valve_infer),"drop",FALSE,NULL);	    
     
 }	    

this code has not any problem on DS4.0 but migrated for DS5.0 code throws a problem
error : (incorrect camera parameters provided, please provide supported resolution and frame rate)
but i didn’t use the wrong resolution and frame rate.
program works normally, but if i change the screenmode repeatedly, it will get an error.

So.

  1. still have memory leak my plugin
  2. got a new camera src problem on DS5.0

could you check my code??

for memory leakage, could you use valgrind to check the leakge?
here is a sample to check the memory leakage

sudo apt-get install valgrind valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./deepstream-test1-app …/…/…/…/samples/streams/sample_720p.h264

Hi @mchi

this is my test result

Runtime commands:
        h: Print this help
        q: Quit

        p: Pause
        r: Resume

NOTE: To expand a source in the 2D tiled display and view object details, left-click on the source.
      To go back to the tiled display, right-click anywhere on the window.


**PERF: FPS 0 (Avg)     FPS 1 (Avg)
**PERF: 0.00 (0.00)     0.00 (0.00)
** INFO: <bus_callback:241>: Pipeline ready

** INFO: <bus_callback:227>: Pipeline running

==11103== Thread 23 src_bin_muxer:sr:
==11103== Syscall param ioctl(generic) points to uninitialised byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x1C4E5D4B: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_gpu.so)
==11103==    by 0x1C4DD833: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_gpu.so)
==11103==    by 0x1B8059BF: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1.1)
==11103==    by 0x1B805D17: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1.1)
==11103==    by 0x1B6FF713: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1.1)
==11103==    by 0x1B671267: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1.1)
==11103==    by 0x1B772857: cuStreamSynchronize (in /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1.1)
==11103==    by 0x1C61F50B: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistream.so)
==11103==  Address 0x8be589e8 is on thread 23's stack
==11103==
==11103== Thread 21 src_elem:src:
==11103== Syscall param ioctl(generic) points to uninitialised byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x1C54F37B: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so)
==11103==    by 0x33D63B97: NvDdkVicExecute (in /usr/lib/aarch64-linux-gnu/tegra/libnvddk_vic.so)
==11103==    by 0x332A7933: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x332ABCFF: NvBufSurfTransform (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x37DD3F33: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libgstnvvideoconvert.so)
==11103==    by 0x1246B11F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x65e030f4 is 4 bytes inside a block of size 4,096 alloc'd
==11103==    at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== Conditional jump or move depends on uninitialised value(s)
==11103==    at 0x1C54F3D4: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so)
==11103==    by 0x33D63B97: NvDdkVicExecute (in /usr/lib/aarch64-linux-gnu/tegra/libnvddk_vic.so)
==11103==    by 0x332A7933: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x332ABCFF: NvBufSurfTransform (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x37DD3F33: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libgstnvvideoconvert.so)
==11103==    by 0x1246B11F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==
==11103== Syscall param ioctl(generic) points to uninitialised byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x1C54F683: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so)
==11103==    by 0x332A7CDF: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x332ABCFF: NvBufSurfTransform (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x37DD3F33: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libgstnvvideoconvert.so)
==11103==    by 0x1246B11F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x8ae55040 is on thread 21's stack
==11103==
**PERF: 0.00 (0.00)     0.00 (0.00)
==11103== Thread 16 tiled_display_qu:
==11103== Syscall param ioctl(generic) points to uninitialised byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x1C54F37B: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so)
==11103==    by 0x33D63B97: NvDdkVicExecute (in /usr/lib/aarch64-linux-gnu/tegra/libnvddk_vic.so)
==11103==    by 0x332A7103: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x332AB72F: NvBufSurfTransformComposite (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x388D6167: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistreamtiler.so)
==11103==    by 0x388D1867: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistreamtiler.so)
==11103==    by 0x1246B11F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x65d46844 is 4 bytes inside a block of size 4,096 alloc'd
==11103==    at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== Conditional jump or move depends on uninitialised value(s)
==11103==    at 0x1C54F3D4: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so)
==11103==    by 0x33D63B97: NvDdkVicExecute (in /usr/lib/aarch64-linux-gnu/tegra/libnvddk_vic.so)
==11103==    by 0x332A7103: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x332AB72F: NvBufSurfTransformComposite (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x388D6167: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistreamtiler.so)
==11103==    by 0x388D1867: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistreamtiler.so)
==11103==    by 0x1246B11F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==
==11103== Syscall param ioctl(generic) points to uninitialised byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x1C54F683: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so)
==11103==    by 0x332A72F7: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x332AB72F: NvBufSurfTransformComposite (in /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0)
==11103==    by 0x388D6167: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistreamtiler.so)
==11103==    by 0x388D1867: ??? (in /opt/nvidia/deepstream/deepstream-5.0/lib/gst-plugins/libnvdsgst_multistreamtiler.so)
==11103==    by 0x1246B11F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x65b04070 is on thread 16's stack
==11103==
==11103== Thread 9:
==11103== Syscall param ioctl(generic) points to unaddressable byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x34549EA7: nvdcOpen (in /usr/lib/aarch64-linux-gnu/tegra/libnvdc.so)
==11103==    by 0x3D35765F: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x3D334307: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x3D315B3B: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x3D31FD77: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x1C5DF627: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvos.so)
==11103==    by 0x12721087: start_thread (pthread_create.c:463)
==11103==    by 0x4F454EB: thread_start (clone.S:78)
==11103==  Address 0x7 is not stack'd, malloc'd or (recently) free'd
==11103==
==11103== Syscall param ioctl(generic) points to unaddressable byte(s)
==11103==    at 0x4F3DB1C: ioctl (ioctl.S:26)
==11103==    by 0x34544AB7: nvdcGetWindow (in /usr/lib/aarch64-linux-gnu/tegra/libnvdc.so)
==11103==    by 0x3D3576E7: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x3D334307: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x3D315B3B: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x3D31FD77: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==11103==    by 0x1C5DF627: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvos.so)
==11103==    by 0x12721087: start_thread (pthread_create.c:463)
==11103==    by 0x4F454EB: thread_start (clone.S:78)
==11103==  Address 0x1 is not stack'd, malloc'd or (recently) free'd
==11103==
swap
**PERF: 0.00 (0.00)     0.00 (0.00)
swap
swap
swap
swap
swap
swap
swap
swap
swap
swap
**PERF: 1.20 (1.08)     0.00 (0.00)
swap
swap
**PERF: 1.78 (1.48)     0.00 (0.00)
m
set menu modeset pn
set cp
set cm
Prepare start
set surface memtype nvbuf_mem_dafault
mat make ok
mat set background ok
Draw Complete
Prepare OK
TransForm OK
**PERF: 2.67 (1.76)     0.00 (0.00)
Prepare start
set surface memtype nvbuf_mem_dafault
mat make ok
mat set background ok
Draw Complete
Prepare OK
TransForm OK
Prepare start
set surface memtype nvbuf_mem_dafault
mat make ok
mat set background ok
Draw Complete
Prepare OK
TransForm OK
Prepare start
set surface memtype nvbuf_mem_dafault
mat make ok
mat set background ok
Draw Complete
Prepare OK
TransForm OK
==11103== Thread 11 render_queue1:sr:
==11103== Invalid read of size 4
==11103==    at 0x37E6DD14: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==11103==    by 0x1245FB9F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x849a9ff4 is 4 bytes inside a block of size 64 free'd
==11103==    at 0x4845D58: free (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==  Block was alloc'd at
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== Invalid read of size 8
==11103==    at 0x37E6DE90: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==11103==    by 0x1245FB9F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x849aa008 is 24 bytes inside a block of size 64 free'd
==11103==    at 0x4845D58: free (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==  Block was alloc'd at
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== Invalid read of size 8
==11103==    at 0x37E6DEA0: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==11103==    by 0x1245FB9F: ??? (in /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so.0.1405.0)
==11103==  Address 0x849aa098 is 40 bytes inside a block of size 384 free'd
==11103==    at 0x4845D58: free (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==  Block was alloc'd at
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== Invalid read of size 8
==11103==    at 0x4849F70: __GI_memcpy (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==11103==
==11103==
==11103== Process terminating with default action of signal 11 (SIGSEGV)
==11103==  Access not within mapped region at address 0x0
==11103==    at 0x4849F70: __GI_memcpy (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==  If you believe this happened as a result of a stack
==11103==  overflow in your program's main thread (unlikely but
==11103==  possible), you can try to increase the size of the
==11103==  main thread stack using the --main-stacksize= flag.
==11103==  The main thread stack size used in this run was 8388608.
==11103==
==11103== HEAP SUMMARY:
==11103==     in use at exit: 1,005,657,568 bytes in 563,750 blocks
==11103==   total heap usage: 922,079 allocs, 358,329 frees, 1,343,390,860 bytes allocated
==11103==
==11103== Thread 1:
==11103== 112 bytes in 6 blocks are indirectly lost in loss record 1 of 24
==11103==    at 0x4844B3C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 208 bytes in 13 blocks are possibly lost in loss record 2 of 24
==11103==    at 0x4844B3C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 256 bytes in 1 blocks are indirectly lost in loss record 3 of 24
==11103==    at 0x4846D10: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 896 bytes in 16 blocks are still reachable in loss record 4 of 24
==11103==    at 0x4845B5C: operator new[](unsigned long, std::nothrow_t const&) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 1,056 bytes in 33 blocks are still reachable in loss record 5 of 24
==11103==    at 0x4BF050C: g_closure_new_simple (in /usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11103==
==11103== 1,336 bytes in 33 blocks are still reachable in loss record 6 of 24
==11103==    at 0x4BF04C4: g_closure_new_simple (in /usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11103==
==11103== 2,632 bytes in 8 blocks are still reachable in loss record 7 of 24
==11103==    at 0x48458F4: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 3,664 bytes in 26 blocks are possibly lost in loss record 8 of 24
==11103==    at 0x4846D10: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 7,903 (1,280 direct, 6,623 indirect) bytes in 2 blocks are definitely lost in loss record 9 of 24
==11103==    at 0x4846D10: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 12,133 bytes in 282 blocks are indirectly lost in loss record 10 of 24
==11103==    at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 27,168 (18,858 direct, 8,310 indirect) bytes in 38 blocks are definitely lost in loss record 11 of 24
==11103==    at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 27,232 bytes in 611 blocks are still reachable in loss record 12 of 24
==11103==    at 0x4C17D84: g_type_create_instance (in /usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11103==
==11103== 66,472 (336 direct, 66,136 indirect) bytes in 6 blocks are definitely lost in loss record 13 of 24
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 68,568 bytes in 115 blocks are indirectly lost in loss record 14 of 24
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 82,692 bytes in 1,258 blocks are possibly lost in loss record 15 of 24
==11103==    at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 132,928 bytes in 18 blocks are still reachable in loss record 16 of 24
==11103==    at 0x4845494: operator new(unsigned long, std::nothrow_t const&) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 181,704 bytes in 611 blocks are still reachable in loss record 17 of 24
==11103==    at 0x4C17D3C: g_type_create_instance (in /usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11103==
==11103== 187,608 bytes in 907 blocks are still reachable in loss record 18 of 24
==11103==    at 0x4844B3C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 280,455 bytes in 1,803 blocks are still reachable in loss record 19 of 24
==11103==    at 0x4846D10: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 542,237 bytes in 5,769 blocks are still reachable in loss record 20 of 24
==11103==    at 0x484522C: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 2,431,261 bytes in 15,626 blocks are possibly lost in loss record 21 of 24
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 18,835,624 bytes in 87 blocks are still reachable in loss record 22 of 24
==11103==    at 0x4846E5C: memalign (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 278,104,456 bytes in 264,081 blocks are still reachable in loss record 23 of 24
==11103==    at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== 704,518,668 bytes in 271,756 blocks are still reachable in loss record 24 of 24
==11103==    at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==11103==
==11103== LEAK SUMMARY:
==11103==    definitely lost: 20,474 bytes in 46 blocks
==11103==    indirectly lost: 81,069 bytes in 404 blocks
==11103==      possibly lost: 2,517,825 bytes in 16,923 blocks
==11103==    still reachable: 1,002,816,832 bytes in 545,733 blocks
==11103==                       of which reachable via heuristic:
==11103==                         stdstring          : 93,734 bytes in 1,740 blocks
==11103==                         length64           : 1,064 bytes in 23 blocks
==11103==                         newarray           : 8,488 bytes in 45 blocks
==11103==                         multipleinheritance: 7,888 bytes in 8 blocks
==11103==         suppressed: 0 bytes in 0 blocks
==11103==
==11103== For counts of detected and suppressed errors, rerun with: -v
==11103== Use --track-origins=yes to see where uninitialised values come from
==11103== ERROR SUMMARY: 1115 errors from 27 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)  

Which part of the code should I modify?

my code is plugin source

Hi @jchcdev,
In gst_menudraw_prepare_output_buffer(), I saw there are two NvBufSurfaceCreate() calls to allocated tow buffers, but they are not freed. Could you free them to check if memory leakage is still there ?

In Process_Draw_Menu(), seems there is not leak.

Thanks!

hi @mchi

gst_menudraw_prepare_output_buffer is only has one NvBufSurfaceCreate()

//Make GST Buffer
if (NvBufSurfaceCreate (&(menudraw->inter_buf), 1,
&create_params) != 0) {
GST_ERROR (“Error: Could not allocate internal buffer for menudraw”);
goto error;
}
menudraw->inter_buf->numFilled = 1;

and i freed the Surface before Create

if (menudraw->inter_buf)
NvBufSurfaceDestroy (menudraw->inter_buf);
menudraw->inter_buf = NULL;

/* An intermediate buffer for NV12/RGBA to BGR conversion will be
/*required. Can be skipped if custom algorithm can work directly on NV12/RGBA. */
/create_params.gpuId = menudraw->gpu_id;
create_params.width = menudraw->processing_width;
create_params.height = menudraw->processing_height;
create_params.size = 0;
create_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
create_params.layout = NVBUF_LAYOUT_PITCH;
#ifdef aarch64
create_params.memType = NVBUF_MEM_DEFAULT;
g_print(“set surface memtype nvbuf_mem_dafault\n”);
#else
create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
#endif
//Make GST Buffer
if (NvBufSurfaceCreate (&newoutsurface, 1,
&create_params) != 0) {
GST_ERROR (“Error: Could not allocate internal buffer for menudraw”);
goto error;
}
newoutsurface->numFilled = 1;
/

this Create block is comment

i think i freed Surface using NvBufSurfaceDestroy

And if i place the destructive command at the bottom of the function, the screen does not display.

plz check again ?? my source plugin source

In the code you pasted in the top of this post, there are two NvBufSurfaceCreate () , is it a mistake?

below code is comment

my function routine

DestroySurface[if inter_buf not 0] - CreateSurface(inter_buf] - makegstbuffer[outbuf] - map - Process_DrawMenu[drawmenu on mat] - unmap - return;

I thought outbuf should not be free because it is used in the next plug-in.

Ok, got it. One more question, how do you check the “3mb leak”?

i use command "free -s 1 " on terminal

up down 3 mb/sec of leakage occurs when drawing in my plug-in.

and

If i comment all the codes in the prepare_output function, no memory-licks will occur.

So I suspected that memory leak occurred in the process of making my Process_Draw_Menu function or make_gstbuffer.

could you help me ??

if you need i’ll send all of my code (deepstream-app and plugin]

or i can give source or compiled file.

++
And after the migration from 4.0 to 5.0, there was a new bug.

i am using the valve plugin to swap “inference plugin” and “menudraw plugin” now.

but If i change the drop property of the valve several times. The error below occurs and the program stops.
error : (incorrect camera parameters provided, please provide supported resolution and frame rate)
this can be checked by looking at the deepstream-app code I modified.

This does not occur in DS4.0.

did you solve this problem?