linux: Fix possible double-close on exit

Fix double-close on exit. If we created a GIOChannel from the file
descriptor, then g_io_channel_shutdown() will close that file descriptor
as well. Close the channel first, so that the file descriptor is only
closed manually if we didn't manage to create a GIOChannel from it.

https://gitlab.freedesktop.org/upower/upower/issues/60
This commit is contained in:
Bastien Nocera 2018-06-19 13:10:24 +02:00
parent 0e51436b4b
commit 054cb3f4b8

View file

@ -286,12 +286,13 @@ up_input_finalize (GObject *object)
g_return_if_fail (input->priv != NULL);
g_clear_object (&input->priv->daemon);
if (input->priv->eventfp >= 0)
close (input->priv->eventfp);
if (input->priv->channel) {
g_io_channel_shutdown (input->priv->channel, FALSE, NULL);
input->priv->eventfp = -1;
g_io_channel_unref (input->priv->channel);
}
if (input->priv->eventfp >= 0)
close (input->priv->eventfp);
G_OBJECT_CLASS (up_input_parent_class)->finalize (object);
}