]> git.feebdaed.xyz Git - 0xmirror/pigpio.git/commitdiff
V68+: #261 close gpio ISR fd when ISR cancelled.
authorjoan2937 <joan@abyz.me.uk>
Tue, 2 Jul 2019 17:38:19 +0000 (18:38 +0100)
committerjoan2937 <joan@abyz.me.uk>
Tue, 2 Jul 2019 17:38:19 +0000 (18:38 +0100)
pigpio.c
pigpio.h

index 1126ec35fab984ae6ec94d71564195cd9ebf0f45..56c348966e6171bf5fdf88712c27081627beed8d 100644 (file)
--- 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;
       }
index 03ebdca139955efdbc038dd9b42640bf42d52a08..046af933f4fd383bb5f502ee71d908f8e9956dd4 100644 (file)
--- a/pigpio.h
+++ b/pigpio.h
@@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
 #include <stdint.h>
 #include <pthread.h>
 
-#define PIGPIO_VERSION 6904
+#define PIGPIO_VERSION 6905
 
 /*TEXT