From 7ef99aee4240f9cf39f1cc0a1347e2bb94c80e78 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 2 Jul 2019 18:38:19 +0100 Subject: [PATCH] V68+: #261 close gpio ISR fd when ISR cancelled. --- pigpio.c | 12 ++++++++++++ pigpio.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 1126ec3..56c3489 100644 --- a/pigpio.c +++ b/pigpio.c @@ -970,6 +970,7 @@ typedef struct int timeout; unsigned ex; void *userdata; + int fd; int inited; } gpioISR_t; @@ -11477,12 +11478,16 @@ static void *pthISRThread(void *x) sprintf(buf, "/sys/class/gpio/gpio%d/value", isr->gpio); + isr->fd = -1; /* no fd assigned */ + if ((fd = open(buf, O_RDONLY)) < 0) { DBG(DBG_ALWAYS, "gpio %d not exported", isr->gpio); return NULL; } + isr->fd = fd; /* store fd so it can be closed */ + pfd.fd = fd; pfd.events = POLLPRI; @@ -11602,6 +11607,13 @@ static int intGpioSetISRFunc( if (gpioISR[gpio].pth) /* delete any existing ISR */ { gpioStopThread(gpioISR[gpio].pth); + + if (gpioISR[gpio].fd >= 0) + { + close(gpioISR[gpio].fd); + gpioISR[gpio].fd = -1; + } + gpioISR[gpio].func = NULL; gpioISR[gpio].pth = NULL; } diff --git a/pigpio.h b/pigpio.h index 03ebdca..046af93 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6904 +#define PIGPIO_VERSION 6905 /*TEXT