Free(): Invalid Pointer with 5.0-20.07-devel (dGPU) and 5.0-20.07-samples (Jetson)

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson Nano and RTX2080)
**• DeepStream Version v5.0
• JetPack Version (4.4 R32.4.3)
**• TensorRT Version 7.1.3
• NVIDIA GPU Driver Version (450.51.06)
• Issue Type( bugs)
• How to reproduce the issue ? (deepstream_test4_app.c)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

Hello,

An invalid pointer error occurs in the following code at g_free() for both my dGPU and Jetson Nano when updating from 5.0-dp-20.04 to 5.0-20.07. It runs fine on 5.0-dp-20.04 for dGPU and Jetson.

		NvOSD_TextParams *txt_params = NULL;
		txt_params = &(obj_meta->text_params);
		if (txt_params->display_text) {
			/* This line causes 'invalid pointer' error on 5.0-20.07-devel (dGPU) and 5.0-20.07-samples (Jetson) */
			g_free(txt_params->display_text); 
		}
		txt_params->display_text = (gchar*)g_malloc0(MAX_DISPLAY_LEN);

Your help is welcome :)

  • B

Hi,
Looks like txt_params->display_text is not allocated. Please allocate the memory at the fist time.

This is essentially how it is written in the NVIDIA deepstream_test4_app.c in the function osd_sink_pad_buffer_probe() on lines 322-326. The memory allocation is after the g_free, which does not really make sense to me. However, it works fine for 5.0-dp-20.04, but not 5.0-20.07.

Your continued help is welcome.

Hi brad_user,

We tried deepstream-test4 on Jetson-Nano with JP-4.4 GA + Deepstream-5.0, no issue.
Attached “deepstream-test4_DS-5.0.txt” log for you reference.
You can reference Topic-84215 steps.
deepstream-test4_DS-5.0.txt (81.5 KB)

Here is my function that continues to work fine in 5.0-dp-20.04, but not 5.0-20.07. It fails at line 116 still. Any further help is welcome.

static GstPadProbeReturn
nvtrk_src_pad_probe(GstPad *pad, GstPadProbeInfo *info,
gpointer u_data)
{
GstBuffer *buf = (GstBuffer *)info->data;
NvDsMetaList *l_frame = NULL;
NvDsMetaList *l_obj = NULL;
NvDsMetaList *l_user_meta = NULL;
guint person_count = 0;
guint chair_count = 0;

NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
if (!batch_meta) {
	// No batch meta attached.
	return GST_PAD_PROBE_REMOVE;
}

/* Process frame in batch */
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
	l_frame = l_frame->next)
{
	NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
	if (frame_meta == NULL) { continue; }	// Ignore Null frame meta.

	// Object params		
	std::vector<float> dMaxVal_disp;
	std::vector<std::vector<cv::Point2i> > pointTensor;
	int offset = 0;

	/* Process objects in frame */
	for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
	{
		NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)l_obj->data;
		if (obj_meta == NULL) { continue; }	// Ignore Null obj meta.

		if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
			person_count++;
		}
		if (obj_meta->class_id == PGIE_CLASS_ID_CHAIR) {
			chair_count++;
		}
		
		std::vector<cv::Point2i> spnts;
		if (!dm_metadata->empty())
		{
			cv::Size dmSize = dm_metadata->size();
			getBBoxspnts(&obj_meta->rect_params, dmSize, &spnts);
			pointTensor.push_back(spnts);
		}
	}

	// 7.  Update estimate here	 [code ommited]
	// dMaxVal_disp gets updated
	
	/* Add estimate to nvds object metadata via NvDsUserMeta.
		 Need to Acquire NvDsUserMeta user meta from pool */
	int cnt = 0;
	for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
	{
		/* Set NvDsUserMeta for each object */
		NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)l_obj->data;
		if (obj_meta == NULL) { continue; }	// Ignore Null obj meta.

		NvDsUserMeta *user_meta = nvds_acquire_user_meta_from_pool(batch_meta);
		nvds_acquire_meta_lock(batch_meta);

		if (user_meta == nullptr) {
			GST_WARNING("NvDsUserMeta not found for user_meta from batch pool");
			nvds_release_meta_lock(batch_meta);
			return GST_PAD_PROBE_REMOVE;
		}

		// Update estimate in meta
		user_meta->user_meta_data = (void *)set_metadata_ptr(dMaxVal_disp[cnt]);

		user_meta->base_meta.meta_type = NVDS_USER_OBJECT_META;
		//user_meta->base_meta.copy_func = (NvDsMetaCopyFunc)copy_user_meta;
		//user_meta->base_meta.release_func = (NvDsMetaReleaseFunc)release_user_meta;

		/* Add NvDsUserMeta to object */
		nvds_add_user_meta_to_obj(obj_meta, user_meta);
		nvds_release_meta_lock(batch_meta);

		cnt++;
	}

	/* Update OSD Object label txt_params with estimate */
	gfloat *dEst = NULL;
	for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
	{
		NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)l_obj->data;
		if (obj_meta == NULL) { continue; }	// Ignore Null obj meta.

		for (l_user_meta = obj_meta->obj_user_meta_list; l_user_meta != NULL;
			l_user_meta = l_user_meta->next)
		{
			NvDsUserMeta *user_meta = (NvDsUserMeta *)l_user_meta->data;
			if (user_meta == NULL) { continue; }	// Ignore Null user meta.

			dEst = (gfloat *)user_meta->user_meta_data;
		}

		NvOSD_TextParams *txt_params = NULL;
		txt_params = &(obj_meta->text_params);
		if (txt_params->display_text) {
			/* This line causes 'invalid pointer' error on 5.0-20.07-devel (dGPU) and 5.0-20.07-samples (Jetson) */
			g_free(txt_params->display_text);
		}

		txt_params->display_text = (gchar*)g_malloc0(MAX_DISPLAY_LEN);
		g_snprintf(txt_params->display_text, MAX_DISPLAY_LEN, "%s %lu [%1.2fm]",
			obj_meta->obj_label, obj_meta->object_id, *dEst);

		// Set the offsets where string should appear on bbox
		txt_params->x_offset = obj_meta->rect_params.left;
		txt_params->y_offset = obj_meta->rect_params.top - 25;

		// Font , font-color and font-size
		txt_params->font_params.font_name = strdup("Serif");
		txt_params->font_params.font_size = 10;
		txt_params->font_params.font_color.red = 1.0;
		txt_params->font_params.font_color.green = 1.0;
		txt_params->font_params.font_color.blue = 1.0;
		txt_params->font_params.font_color.alpha = 1.0;

		// Text background color
		txt_params->set_bg_clr = 1;
		txt_params->text_bg_clr.red = 0.0;
		txt_params->text_bg_clr.green = 0.0;
		txt_params->text_bg_clr.blue = 0.0;
		txt_params->text_bg_clr.alpha = 1.0;

		// Console output - DEBUGGING
		g_print("[%d] - obj_meta[%lu]: %d (%s) (%1.2fm)\n", frame_number,
			obj_meta->object_id, obj_meta->class_id, obj_meta->obj_label,
			*dEst);
	}
	g_print("\n");

	/* Update OSD display overlay metadata */
	NvDsDisplayMeta *display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
	NvOSD_TextParams *txt_params = &display_meta->text_params[0];
	display_meta->num_labels = 1;
	txt_params->display_text = (gchar*)g_malloc0(MAX_DISPLAY_LEN);

	offset =
		snprintf(txt_params->display_text, MAX_DISPLAY_LEN, "[%d] Person = %d ",
			frame_number, person_count);
	offset =
		snprintf(txt_params->display_text + offset, MAX_DISPLAY_LEN,
			"Chair = %d ", chair_count);

	// Now set the offsets where the string should appear
	txt_params->x_offset = 10;
	txt_params->y_offset = 12;

	// Font , font-color and font-size
	txt_params->font_params.font_name = strdup("Serif");
	txt_params->font_params.font_size = 10;
	txt_params->font_params.font_color.red = 1.0;
	txt_params->font_params.font_color.green = 1.0;
	txt_params->font_params.font_color.blue = 1.0;
	txt_params->font_params.font_color.alpha = 1.0;

	// Text background color
	txt_params->set_bg_clr = 1;
	txt_params->text_bg_clr.red = 0.0;
	txt_params->text_bg_clr.green = 0.0;
	txt_params->text_bg_clr.blue = 0.0;
	txt_params->text_bg_clr.alpha = 1.0;

	nvds_add_display_meta_to_frame(frame_meta, display_meta);
}

frame_number++; // Global update

return GST_PAD_PROBE_REMOVE;

}

Cheers, B

Hi,
So are you able to run the default sample successfully? Or it fails with the patch?

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

Hi,
Please make a patch to deepstream-test4 so that we can give it a try. There is osd_sink_pad_buffer_probe() in the sample and no nvtrk_src_pad_probe(). We would need a full patch.