Restarting the pipeline leads to seg fault

• Hardware Platform (Jetson / GPU) - Jetson nano
• DeepStream Version 5.0
• JetPack Version (valid for Jetson only) 4.4
• TensorRT Version 7.1
• Issue Type( questions, new requirements, bugs) bug

I was playing around with the source code of deepstream reference app which comes with deepstream sdk.
I am using live rtsp sources as input. The app works fine for the initial run.

So as given in the source code -
when the app encounters an error it goes to done and performs the required cleanup.

done:
	g_print ("Quitting\n");
    g_source_remove(event_source_id);
    g_source_remove(timeout_source);
	for (i = 0; i < num_instances; i++) {
	if (appCtx[i]->return_value == -1)
	  return_value = -1;
	int return_after_destroy = destroy_pipeline (appCtx[i]);

	g_mutex_lock (&disp_lock);
	if (windows[i])
	  XDestroyWindow (display, windows[i]);
	windows[i] = 0;
	g_mutex_unlock (&disp_lock);

	g_free (appCtx[i]);
	}

	g_mutex_lock (&disp_lock);
	if (display)
	XCloseDisplay (display);
	display = NULL;
	g_mutex_unlock (&disp_lock);
	g_mutex_clear (&disp_lock);

	if (main_loop) {
	g_main_loop_unref (main_loop);
	}

	if (ctx) {
	g_option_context_free (ctx);
	}

	if (return_value == 0) {
	g_print ("App run successful\n");
	} else {
	g_print ("App run failed\n");
	}

I wish to have a restart function in the app so that when it crashes it again restarts the process after sometime. In order to do that, I wrote a wrapper main function and changed the original function to some other function.

// updated main
int main(int argc, char* argv)
{
   some_other_function(argc, argv);// original main
}

and now am calling some other function again whenever the app goes to the done state. The app runs fine for the first time , but when I am recalling the function for the second time, I get the seg fault just before the main loop is about to be started. How to solve this ?

To simulate a similar behaviour, replace the deepstream_app_main.c file with the attached file in sources/apps/sample-apps/deepstream-app/ directory and rebuild the binary.

What’s the workaround for this ?deepstream_app_main.c (23.2 KB)

I am facing the same issue with the latest deepstream sdk.

please check https://developer.gnome.org/glib/stable/glib-Commandline-option-parser.html#g-option-context-parse

g_option_context_parse ()

Parses the command line arguments, recognizing options which have been added to context . A side-effect of calling this function is that g_set_prgname() will be called.

If the parsing is successful, any parsed arguments are removed from the array and argc and argv are updated accordingly. A ‘–’ option is stripped from argv unless there are unparsed options before and after it, or some of the options after it start with ‘-’. In case of an error, argc and argv are left unmodified.

HI mchi,
Thanks for the quick reply. I made a couple of changes
a) I resetted the argc, argv with values before each restart.
b) I restted the camera_id_list array with NULL before each restart in parse_source function in deepstream_config_parser.c
c) Now, the app doesn’t go into seg fault, but memory leak is still happening and sources etc are not being closed properly. I didnt observed this behaviour in deepstream4.0