The 'struct interface' for the UDS port is allocated on the stack, and
when this gets passed to port_open, the port instance takes a pointer to
the string in the 'name' field. Currently this is harmless for the UDS
port, but it is not good form. This patch fixes the issue by making the
interface part of the clock instance.

Signed-off-by: Richard Cochran <[email protected]>
Reported-by: Miroslav Lichvar <[email protected]>
---
 clock.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clock.c b/clock.c
index 063155b..c99812b 100644
--- a/clock.c
+++ b/clock.c
@@ -98,6 +98,7 @@ struct clock {
        struct clock_stats stats;
        int stats_interval;
        struct clockcheck *sanity_check;
+       struct interface uds_interface;
 };
 
 struct clock the_clock;
@@ -577,20 +578,19 @@ struct clock *clock_create(int phc_index, struct 
interface *iface, int count,
        int i, fadj = 0, max_adj = 0.0, sw_ts = timestamping == TS_SOFTWARE ? 1 
: 0;
        struct clock *c = &the_clock;
        char phc[32];
-       struct interface udsif;
+       struct interface *udsif = &c->uds_interface;
        struct timespec ts;
 
-       memset(&udsif, 0, sizeof(udsif));
-       snprintf(udsif.name, sizeof(udsif.name), "%s", uds_path);
-       udsif.transport = TRANS_UDS;
-       udsif.delay_filter_length = 1;
-
        clock_gettime(CLOCK_REALTIME, &ts);
        srandom(ts.tv_sec ^ ts.tv_nsec);
 
        if (c->nports)
                clock_destroy(c);
 
+       snprintf(udsif->name, sizeof(udsif->name), "%s", uds_path);
+       udsif->transport = TRANS_UDS;
+       udsif->delay_filter_length = 1;
+
        c->free_running = dds->free_running;
        c->freq_est_interval = dds->freq_est_interval;
        c->grand_master_capable = dds->grand_master_capable;
@@ -696,7 +696,7 @@ struct clock *clock_create(int phc_index, struct interface 
*iface, int count,
        /*
         * One extra port is for the UDS interface.
         */
-       c->port[i] = port_open(phc_index, timestamping, 0, &udsif, c);
+       c->port[i] = port_open(phc_index, timestamping, 0, udsif, c);
        if (!c->port[i]) {
                pr_err("failed to open the UDS port");
                return NULL;
-- 
1.7.10.4


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to