Hi, I'm writing something using glib's process spawning features. A silly example of what I'm doing might look something like this:
static void foo (const gchar* path) { gboolean ret; gint stdout; gchar* argv[] = { "/usr/bin/man", "-R", "utf-8", NULL, NULL }; argv[3] = path; ret = g_spawn_async_with_pipes (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, &stdout, NULL, &err); if (!ret) { // Do error handling here } // Use the file descriptor from stdout. }
I've just been browsing through the code in glib's gspawn.c and I *think* that, since it works by calling fork() then exec(), the strings pointed to by argv are copied on the line with the g_spawn_async_with_pipes() call. My first question is, is this right? That is, am I safe to write g_free (path) just before the error-checking code, for example? (Yes, I know that would be silly, but I want to understand what's going on :-) ) If so, I have a second question/suggestion. Should the documentation for the async spawning functions have an explicit comment saying that the memory is copied? Maybe developers with more experience with fork() and exec() see that this is obvious but I, for one, didn't! Thanks, Rupert
Attachment:
pgp1bezV9F5Ue.pgp
Description: PGP signature