title: GStreamer gst_buffer_make_writable seg fault and refcount "hack"
body: <p>I implemented a custom metadata structure for the buffer in GStreamer. To use this structure I created a pad probe and access the buffer with <code>auto buffer = gst_pad_probe_info_get_buffer(info);</code>, where <code>info</code> is a <code>GstPadProbeInfo *info</code>.</p>
  <p>Most elements of the pipeline have writeable buffers and I have no problems with them, but when trying to access the buffer in the sink pad of the queue element it appears that this buffer is not writeable. I already tried to use the <code>buffer = gst_buffer_make_writable(buffer);</code> method but with no luck. I get segmentation faults when using it. I also get a segmentation fault if I just try to create another temporary writable buffer: <code>auto *tmpBuffer = gst_buffer_make_writable(buffer);</code></p>
  <blockquote>
  <p>(rtspserver:23806): GStreamer-CRITICAL **: 09:23:03.442:
  gst_buffer_get_sizes_range: assertion 'GST_IS_BUFFER (buffer)' failed</p>
  <p>(rtspserver:23806): GStreamer-CRITICAL **: 09:23:03.442:
  gst_buffer_copy_into: assertion 'bufsize &gt;= offset' failed</p>
  <p>(rtspserver:23806): GStreamer-CRITICAL **: 09:23:03.442:
  gst_buffer_get_sizes_range: assertion 'GST_IS_BUFFER (buffer)' failed</p>
  <p>(rtspserver:23806): GStreamer-CRITICAL **: 09:23:03.443:
  gst_buffer_extract: assertion 'GST_IS_BUFFER (buffer)' failed</p>
  <p>(rtspserver:23806): GStreamer-CRITICAL **: 09:23:03.443:
  gst_buffer_foreach_meta: assertion 'buffer != NULL' failed</p>
  <p>(rtspserver:23806): GStreamer-CRITICAL **: 09:23:03.443:
  gst_buffer_append_region: assertion 'GST_IS_BUFFER (buf2)' failed
  Segmentation fault</p>
  </blockquote>
  <p>Another thing I tried is to copy the buffer to another temporary buffer <code>auto *tmpBuffer = gst_buffer_copy(buffer);</code>, but then I also have problem with overwriting <code>gst_buffer_replace(&amp;buffer, tmpBuffer);</code> the original buffer.</p>
  <p>I found a solution/hack: I increase the refcount <code>buffer = gst_buffer_ref(buffer);</code> at the queue element (from 2 to 3) and then access the buffer directly without checking it's writability. After that I unref the buffer <code>gst_buffer_unref(buffer);</code>. This seems to work and I would like to know why. If I do not increase the refcount and try to access the buffer without checking it's writability I get a crash. I know this is unsafe and because of that I would like to somehow make the buffer writeable.</p>