I am calling a function with the following lines:
void call_system_command(const char *command_params)
{
GString *cmd = g_string_sized_new(1024);
g_string_append_printf(cmd, "/bin/bash /path/to/my/script '%s'", command_params);
system(cmd->str);
g_string_free(cmd, TRUE);
}
I am getting segfault in the line with g_string_sized_new. Backtrace from gdb shows:
(gdb) bt
#0 0x000000320ce56264 in g_slice_alloc () from /lib64/libglib-2.0.so.0
#1 0x000000320ce5c3db in g_string_sized_new () from /lib64/libglib-2.0.so.0
....
I have tried exporting G_SLICE=always-malloc, so that instead of glib's own allocator, malloc is used. However the problem remains same. I am still getting segfault in g_slice_alloc. Also I am calling this function 'call_system_command' from multiple threads. Could that be a problem?
The function is a part of plugin that is called by cron every 15 minutes. The segfault does not occur every time the plugin is executed but one every 3-4 days.
Any pointers on further debugging will be helpful.
Thanks in advance.