GLib: release GSubprocess resources

Hi everyone,

can you please give some hints how to properly release GLib subprocess resources

Is it okay to release them (particularly to close pipe’s fds) with g_clear_object(&subprocess) after subprocess termination?

Yes, you should just use g_object_unref()/g_clear_object() on GSubprocess, and cleanup should be handled automatically.

Just remember if you have a running task (e.g. g_subprocess_communicate_utf8()) at the time you unref, it will hold a reference on the object until it completes, then drop the final reference.

1 Like

Thanks for confirmation,
it has worked as that supposed to be, only one thing confused me a bit and caused to reassure: it’s clang-tidy complains on g_clear_object macro (in vi* it looks like on the attached picture) despites that this resource release works without errors and warnings. Suppose that complain is a false-positive.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.