[glib: 1/7] gio-test: fix leak & maybe-uninitialized warning
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/7] gio-test: fix leak & maybe-uninitialized warning
- Date: Tue, 27 Nov 2018 10:53:36 +0000 (UTC)
commit b45d911cc631a2922a4290e1b070de657b5cd3e5
Author: Will Thompson <will willthompson co uk>
Date: Mon Nov 26 15:36:09 2018 +0000
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.
tests/gio-test.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/tests/gio-test.c b/tests/gio-test.c
index d9bd7e357..79b53e294 100644
--- a/tests/gio-test.c
+++ b/tests/gio-test.c
@@ -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_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
- recv_message,
- id);
+ 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, 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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]