]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
* [Bug 2808] GPSD_JSON driver enhancements, step 1.
authorJuergen Perlinger <perlinger@ntp.org>
Fri, 8 May 2015 19:25:22 +0000 (21:25 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Fri, 8 May 2015 19:25:22 +0000 (21:25 +0200)
  Fix crash during cleanup if GPS device not present and char device.

bk: 554d0da2kxmpUmReEeuwviy-u5mekQ

ChangeLog
ntpd/refclock_gpsdjson.c

index 88bf769a78126619a5f1bc8cf930a861f13b14f5..f22c179c9fa20b432642e10ec07637a49402f4e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@
 * [Bug 2804] install-local-data assumes GNU 'find' semantics.
 * [Bug 2806] refclock_jjy.c supports the Telephone JJY.
 * [Bug 2808] GPSD_JSON driver enhancements, step 1.
+  Fix crash during cleanup if GPS device not present and char device.
   Increase internal token buffer to parse all JSON data, even SKY.
   Defer logging of errors during driver init until the first unit is
   started, so the syslog is not cluttered when the driver is not used.
index 99a3b096c971f91a68baf56a054ec3348b30e1d0..0a88cece4d24a2f8291ce536ac71a3372bac890d 100644 (file)
@@ -524,8 +524,10 @@ gpsd_start(
        while ((up = *uscan) != NULL && up->unit != (unit & 0x7F))
                uscan = &up->next_unit;
        if (up == NULL) {
+               /* alloc unit, add to list and increment use count ASAP. */
                up = emalloc_zero(sizeof(*up));
                *uscan = up;
+               ++up->refcount;
 
                /* initialize the unit structure */
                up->logname  = estrdup(refnumtoa(&peer->srcadr));
@@ -551,9 +553,11 @@ gpsd_start(
                                up->logname, up->device);
                        goto dev_fail;
                }
+       } else {
+               /* All set up, just increment use count. */
+               ++up->refcount;
        }
-       up->refcount++;
-
+       
        /* setup refclock processing */
        pp->unitptr = (caddr_t)up;
        pp->io.fd         = -1;
@@ -617,7 +621,11 @@ gpsd_shutdown(
 
        UNUSED_ARG(unit);
 
-       INSIST(up);
+       /* The unit pointer might have been removed already. */
+       if (up == NULL)
+               return;
+
+       /* now check if we must close IO resources */
        if (peer != up->pps_peer) {
                if (-1 != pp->io.fd) {
                        DPRINTF(1, ("%s: closing clock, fd=%d\n",
@@ -628,6 +636,7 @@ gpsd_shutdown(
                if (up->fdt != -1)
                        close(up->fdt);
        }
+       /* decrement use count and eventually remove this unit. */
        if (!--up->refcount) {
                /* unlink this unit */
                while (*uscan != NULL)