If both the -w and -O command line options are specified (or when using -w when both source and destination clocks are PHCs), then pointer to the PMC agent will be incorrectly freed.
Fix the segfault by introducing a method to "disable" the agent as was done before the PMC agent code was introduced. Unfortunately the resulting PMC agent API now has both create/destroy and init/disable methods. This clunky arrangement can be cleaned up later on, but it entails re-factoring the phc2sys program even more. Signed-off-by: Richard Cochran <richardcoch...@gmail.com> Fixes: 8266987 ("pmc_agent: Hide the implementation.") --- phc2sys.c | 7 ++----- pmc_agent.c | 8 ++++++++ pmc_agent.h | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 999d20e..7ff7700 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -1315,8 +1315,7 @@ int main(int argc, char *argv[]) if (priv.forced_sync_offset || (src->clkid != CLOCK_REALTIME && dst->clkid != CLOCK_REALTIME) || src->clkid == CLOCK_INVALID) { - pmc_agent_destroy(priv.node); - priv.node = NULL; + pmc_agent_disable(priv.node); } } @@ -1331,9 +1330,7 @@ int main(int argc, char *argv[]) } end: - if (priv.node) { - pmc_agent_destroy(priv.node); - } + pmc_agent_destroy(priv.node); clock_cleanup(&priv); port_cleanup(&priv); config_destroy(cfg); diff --git a/pmc_agent.c b/pmc_agent.c index 22af306..833d1c1 100644 --- a/pmc_agent.c +++ b/pmc_agent.c @@ -366,6 +366,14 @@ void pmc_agent_destroy(struct pmc_agent *agent) free(agent); } +void pmc_agent_disable(struct pmc_agent *agent) +{ + if (agent->pmc) { + pmc_destroy(agent->pmc); + } + agent->pmc = NULL; +} + int pmc_agent_get_leap(struct pmc_agent *agent) { return agent->leap; diff --git a/pmc_agent.h b/pmc_agent.h index 483a21b..0ed10f8 100644 --- a/pmc_agent.h +++ b/pmc_agent.h @@ -55,6 +55,12 @@ struct pmc_agent *pmc_agent_create(void); */ void pmc_agent_destroy(struct pmc_agent *agent); +/** + * Disconnects the PMC agent from the ptp4l service. + * @param agent Pointer to a PMC instance obtained via @ref pmc_agent_create(). + */ +void pmc_agent_disable(struct pmc_agent *agent); + /** * Gets the current leap adjustment. * @param agent Pointer to a PMC instance obtained via @ref pmc_agent_create(). -- 2.20.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel