summaryrefslogtreecommitdiff
path: root/libgps.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-06-28 01:26:20 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-06-28 01:26:20 +0000
commit364d6ce3ddda7aeabb4446b6f5b6fb7fb2b62df0 (patch)
treeda79d1e98eaa3a8d8bd9bce587813957fc1864cb /libgps.c
parentdde64ef97389884f0d79e48f39418d6bb51541b0 (diff)
downloadgpsd-364d6ce3ddda7aeabb4446b6f5b6fb7fb2b62df0.tar.gz
Eliminate dynamic-memory allocation from the daemon.
Only one calloc() is left, and that belongs to Gary in the Garmin driver.
Diffstat (limited to 'libgps.c')
-rw-r--r--libgps.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/libgps.c b/libgps.c
index 455d3a7c..e05fe2c2 100644
--- a/libgps.c
+++ b/libgps.c
@@ -103,13 +103,11 @@ int gps_close(struct gps_data_t *gpsdata)
/* close a gpsd connection */
{
int retval = close(gpsdata->gps_fd);
- if (gpsdata->gps_id)
+ if (gpsdata->gps_id) {
(void)free(gpsdata->gps_id);
gpsdata->gps_id = NULL;
- if (gpsdata->gps_device) {
- (void)free(gpsdata->gps_device);
- gpsdata->gps_device = NULL;
}
+ gpsdata->gps_device[0] = '\0';
if (gpsdata->devicelist) {
int i;
for (i = 0; i < gpsdata->ndevices; i++)
@@ -186,11 +184,11 @@ static void gps_unpack(char *buf, struct gps_data_t *gpsdata)
case 'F':
/*@ -mustfreeonly */
if (sp[2] == '?')
- gpsdata->gps_device = NULL;
+ gpsdata->gps_device[0] = '\0';
else {
- if (gpsdata->gps_device)
- free(gpsdata->gps_id);
- gpsdata->gps_device = strdup(sp+2);
+ /*@ -mayaliasunique @*/
+ strncpy(gpsdata->gps_device, sp+2, PATH_MAX);
+ /*@ +mayaliasunique @*/
gpsdata->set |= DEVICE_SET;
}
/*@ +mustfreeonly */