Encoding jpeg image after OSD causes segfault

The following code is at line 789 of deepstream_app.c:

  if (config->osd_config.enable) {
    NVGSTDS_ELEM_ADD_PROBE(instance_bin->all_bbox_buffer_probe_id,
                           instance_bin->osd_bin.nvosd, "sink",
                           gie_processing_done_buf_prob,
                           GST_PAD_PROBE_TYPE_BUFFER, instance_bin);
  } else {
    NVGSTDS_ELEM_ADD_PROBE(instance_bin->all_bbox_buffer_probe_id,
                           instance_bin->sink_bin.bin, "sink",
                           gie_processing_done_buf_prob,
                           GST_PAD_PROBE_TYPE_BUFFER, instance_bin);
  }
  if (config->image_save_config.enable) {
    NVGSTDS_ELEM_ADD_PROBE(appCtx->pipeline.img_save_buffer_probe_id, 
                           instance_bin->sink_bin.bin, "sink", 
                           img_save_buf_prob, 
                           GST_PAD_PROBE_TYPE_BUFFER, appCtx);
  }

I added the NVGSTDS_ELEM_ADD_PROBE at the end.

The probe function img_save_buf_prob is the same structure as the other buffer probes, and uses the same routine for saving images as in the deepstream-image-meta-test sample app.

The code works fine when OSD is disabled (set enabled=0), but I receive a segfault when OSD is enabled.