mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-02 17:26:17 +01:00
gio-test: fix leak & maybe-uninitialized warning
GCC 8 on F29 complains: ../tests/gio-test.c: In function ‘main’: ../tests/gio-test.c:375:7: warning: ‘id’ may be used uninitialized in this function [-Wmaybe-uninitialized] g_free (id); ^~~~~~~~~~~ In the normal case, when run without arguments, 'id' will be assigned exactly once, so all is fine. If run with argument '0', 'id' will never be assigned, so the warning is legit; but in that case the test program will never exit. If run with any argument greater than 1, 'id' will be assigned more than once but only the last incarnation will be freed. Tweak the scope of the variable to match its use, and arrange for it to be freed when its watch is destroyed.
This commit is contained in:
parent
4326d5e27d
commit
b45d911cc6
@ -266,7 +266,6 @@ main (int argc,
|
||||
|
||||
GIOChannel *my_read_channel;
|
||||
gchar *cmdline;
|
||||
guint *id;
|
||||
int i;
|
||||
#ifdef G_OS_WIN32
|
||||
GTimeVal start, end;
|
||||
@ -316,6 +315,7 @@ main (int argc,
|
||||
for (i = 0; i < nkiddies; i++)
|
||||
{
|
||||
int pipe_to_sub[2], pipe_from_sub[2];
|
||||
guint *id;
|
||||
|
||||
if (pipe (pipe_to_sub) == -1 ||
|
||||
pipe (pipe_from_sub) == -1)
|
||||
@ -328,10 +328,11 @@ main (int argc,
|
||||
|
||||
id = g_new (guint, 1);
|
||||
*id =
|
||||
g_io_add_watch (my_read_channel,
|
||||
g_io_add_watch_full (my_read_channel,
|
||||
G_PRIORITY_DEFAULT,
|
||||
G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
|
||||
recv_message,
|
||||
id);
|
||||
id, g_free);
|
||||
|
||||
nrunning++;
|
||||
|
||||
@ -372,7 +373,6 @@ main (int argc,
|
||||
|
||||
g_main_loop_unref (main_loop);
|
||||
g_free (seqtab);
|
||||
g_free (id);
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user