[Git][NTPsec/ntpsec][master] Reduce memory usage by removing an unneeded strdup().

Eric S. Raymond gitlab at mg.gitlab.com
Sat Sep 16 23:21:11 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
abd7713a by Eric S. Raymond at 2017-09-16T23:20:59Z
Reduce memory usage by removing an unneeded strdup().

- - - - -


1 changed file:

- ntpd/refclock_trimble.c


Changes:

=====================================
ntpd/refclock_trimble.c
=====================================
--- a/ntpd/refclock_trimble.c
+++ b/ntpd/refclock_trimble.c
@@ -318,6 +318,7 @@ trimble_start (
 	struct termios tio;
 	struct calendar build_date;
 	unsigned int cflag, iflag;
+	char device[20], *path;
 
 	pp = peer->procptr;
 	pp->clockname = NAME;
@@ -325,9 +326,11 @@ trimble_start (
 	/*
 	 * Open serial port. 
 	 */
-	if ( !peer->cfg.path ) {
+	if (peer->cfg.path)
+	    path = peer->cfg.path;
+	else
+	{
 	    int rcode;
-	    char device[20];
 	    snprintf(device, sizeof(device), DEVICE, unit);
 
 	    /* build a path */
@@ -336,20 +339,20 @@ trimble_start (
 	        /* failed, set to NUL */
 	        device[0] = '\0';
 	    }
-	    peer->cfg.path = estrdup( device );
+	    path = device;
         }
-	fd = refclock_open(peer->cfg.path,
+	fd = refclock_open(path,
 				  peer->cfg.baud ? peer->cfg.baud : SPEED232,
 				  LDISC_RAW);
 	if (0 > fd) {
 	        msyslog(LOG_ERR, "REFCLOCK: %s Trimble device open(%s) failed",
-			refclock_name(peer), peer->cfg.path);
+			refclock_name(peer), path);
 		/* coverity[leaked_handle] */
 		return false;
 	}
 
 	LOGIF(CLOCKINFO, (LOG_NOTICE, "%s open at %s",
-			  refclock_name(peer), peer->cfg.path));
+			  refclock_name(peer), path));
 
 	if (tcgetattr(fd, &tio) < 0) {
 		msyslog(LOG_ERR, "REFCLOCK: %s tcgetattr failed: %m",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/abd7713a53b45c5b43141c5c7d043e48c8b08d65

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/abd7713a53b45c5b43141c5c7d043e48c8b08d65
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170916/e4222bb0/attachment.html>


More information about the vc mailing list