Nvv4l2h265enc crash problem

I downloaded and checked the source code of ‘nvv4l2h265enc’ from:

In file ‘gstv4l2h265enc.c’, line 391~line 404:

gst_v4l2_is_h265_enc (GstCaps * sink_caps, GstCaps * src_caps)
return gst_v4l2_is_video_enc (sink_caps, src_caps,
gst_static_caps_get (&src_template_caps));

gst_v4l2_h265_enc_register (GstPlugin * plugin, const gchar * basename,
const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
gst_v4l2_video_enc_register (plugin, GST_TYPE_V4L2_H265_ENC,
“h265”, basename, device_path, sink_caps,
gst_static_caps_get (&src_template_caps), src_caps);

These two APIs both call 'gst_static_caps_get() '.
And from:


  • gst_static_caps_get:
  • @static_caps: the #GstStaticCaps to convert
  • Converts a #GstStaticCaps to a #GstCaps.
  • Returns: (transfer full) (nullable): a pointer to the #GstCaps. Since the
  • core holds an additional ref to the returned caps, use
  • gst_caps_make_writable() on the returned caps to modify it.

GstCaps *
gst_static_caps_get (GstStaticCaps * static_caps)
GstCaps **caps;

g_return_val_if_fail (static_caps != NULL, NULL);

caps = &static_caps->caps;

/* refcount is 0 when we need to convert */
if (G_UNLIKELY (*caps == NULL)) {
const char *string;

G_LOCK (static_caps_lock);
/* check if other thread already updated */
if (G_UNLIKELY (*caps != NULL))
  goto done;

string = static_caps->string;

if (G_UNLIKELY (string == NULL))
  goto no_string;

*caps = gst_caps_from_string (string);

/* convert to string */
if (G_UNLIKELY (*caps == NULL)) {
  g_critical ("Could not convert static caps \"%s\"", string);
  goto done;

/* Caps generated from static caps are usually leaked */

GST_CAT_TRACE (GST_CAT_CAPS, "created %p from string %s", static_caps,

G_UNLOCK (static_caps_lock);
/* ref the caps, makes it not writable */
if (G_LIKELY (*caps != NULL))
gst_caps_ref (*caps);

return *caps;

/* ERRORS */
G_UNLOCK (static_caps_lock);
g_warning (“static caps %p string is NULL”, static_caps);
return NULL;

Seems that ‘gst_static_caps_get()’ will return a GstCaps object with refcount >= 1.
And this GstCaps object should be ‘unref’-ed after use, in order to release the object.
However, this release is missed in both ‘gst_v4l2_is_h265_enc’ and ‘gst_v4l2_h265_enc_register’, which may possibly cause the memory leak,
as indicated by :

0:03:33.169063483 30128 0x55a1686040 TRACE GST_TRACER :0:: object-alive, type-name=(string)GstCaps, address=(gpointer)0x7f9808a320, description=(string)video/x-h265, stream-format=(string)byte-stream, alignment=(string)au, ref-count=(uint)1, trace=(string);

hi,danelll,what about the isuue

Do you observe the issue on TX2 developer kit? We have set up r32.5.0/TX2 developer kit and run the python sample. Don’t hit crash and memory increase.

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