From: Juergen Perlinger Date: Fri, 8 May 2015 19:25:22 +0000 (+0200) Subject: * [Bug 2808] GPSD_JSON driver enhancements, step 1. X-Git-Tag: NTP_4_3_32~5^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e704f45e1e556f52614298b4fe71e240ed569d6;p=thirdparty%2Fntp.git * [Bug 2808] GPSD_JSON driver enhancements, step 1. Fix crash during cleanup if GPS device not present and char device. bk: 554d0da2kxmpUmReEeuwviy-u5mekQ --- diff --git a/ChangeLog b/ChangeLog index 88bf769a7..f22c179c9 100644 --- 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. diff --git a/ntpd/refclock_gpsdjson.c b/ntpd/refclock_gpsdjson.c index 99a3b096c..0a88cece4 100644 --- a/ntpd/refclock_gpsdjson.c +++ b/ntpd/refclock_gpsdjson.c @@ -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)