Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[trigger] Fix udev iowatch issues
Various pointers are uninitialized / left to hold stale values after
releasing. Which could lead to hard to debug problems if trigger_stop() is
called multiple times / after unsuccessful trigger_init().

Zero initialize all pointers dealing with dynamic resources and clear them
when resources are released.

Also clear iowatch id when it is going to be implicitly removed due to the
return value from the callback so that removal is not attempted anymore
when/if trigger_stop() is called later on.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jul 7, 2016
1 parent 839fda6 commit 7bc4498
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/usb_moded-trigger.c
Expand Up @@ -43,10 +43,10 @@
#endif /* MEEGOLOCK */

/* global variables */
static struct udev *udev;
static struct udev_monitor *mon;
static GIOChannel *iochannel;
static guint watch_id;
static struct udev *udev = 0;
static struct udev_monitor *mon = 0;
static GIOChannel *iochannel = 0;
static guint watch_id = 0;
static const char *dev_name;

/* static function definitions */
Expand Down Expand Up @@ -138,8 +138,11 @@ static gboolean monitor_udev(GIOChannel *iochannel G_GNUC_UNUSED, GIOCondition c
if (dev)
{
/* check if it is the actual device we want to check */
if(strcmp(dev_name, udev_device_get_sysname(dev)))
return 0;
if(strcmp(dev_name, udev_device_get_sysname(dev))) {
log_crit("name does not match, disabling udev trigger io-watch");
watch_id = 0;
return FALSE;
}

if(!strcmp(udev_device_get_action(dev), "change"))
{
Expand All @@ -152,7 +155,9 @@ static gboolean monitor_udev(GIOChannel *iochannel G_GNUC_UNUSED, GIOCondition c
else
{
log_debug("Bad trigger data. Stopping\n");
watch_id = 0;
trigger_stop();
return FALSE;
}
}

Expand All @@ -162,12 +167,26 @@ static gboolean monitor_udev(GIOChannel *iochannel G_GNUC_UNUSED, GIOCondition c

void trigger_stop(void)
{
g_source_remove(watch_id);
watch_id = 0;
g_io_channel_unref(iochannel);
iochannel = NULL;
udev_monitor_unref(mon);
udev_unref(udev);
if(watch_id)
{
g_source_remove(watch_id);
watch_id = 0;
}
if(iochannel) {
g_io_channel_unref(iochannel);
iochannel = NULL;
}
if(mon)
{
udev_monitor_unref(mon);
mon = 0;
}
if(udev)
{
udev_unref(udev);
udev = 0;
}
dev_name = 0;
}

static void udev_parse(struct udev_device *dev)
Expand Down

0 comments on commit 7bc4498

Please sign in to comment.