gdbus: is it safe to free signal argument right after signal emission

I created simple dbus service that emits signal with dynamically allocated data argument:

file_name = g_strdup("myfile");
...
...
g_signal_emit_by_name (object, "mysignal", file_name);
g_free(file_name);

In this case signal listeners may receive file_name string that was already destroyed.

So is it safe to free file_name right after g_signal_emit_by_name call or I should wait for a few seconds? Or is there any other mechanism to free memory in such cases?

Answers


GSignal emission is synchronous, i.e. all the connected callbacks to a signal are run sequentially by g_signal_emit(), which will return control to you once all callbacks return. thus, it is safe to emit a signal and free the arguments of the signal after g_signal_emit() returns.

if you're using DBus then it's still safe: the data will be copied over to the receiving process(es), as it would be impossible to share it across process boundaries.


I'm not familiar with the gdbus API in particular, but in general for this kind of usage, you want to make it the recipient's responsibility to free the storage. The only exceptions would be when the object is known to have a lifetime that will persist beyond the needs of the recipient (e.g. static storage) or the API handles copying data for you.


Need Your Help

404 not found page not working with my .htaccess

php http-status-code-404

I have below .htaccess on the server with the not found page rules but it doesn't seems to work. Any idea?

vb.net radiobuttonlist containing 3 buttons not firing when selectedindexchanging from index 2 to 0 under one condition

asp.net vb.net datagrid radiobuttonlist sqldatadapter

My code fills a DataGrid control (vb.net 3.5 framework) using sqldataadapter and dataset, filtered by selections from a combination of other controls. Everything works fine except RadioButtonList1 ...