The ts2phc program keeps track of the allocated configuration in its
"private" data structure, duly freeing it during the cleanup method.
However, the assignment of the priv.cfg field occurs after many
possible calls to the ts2phc_cleanup() function, resulting in a memory
leak.  Fix the issue by assigning the field prior to the first
invocation of the cleanup method.

Signed-off-by: Richard Cochran <[email protected]>
---
 ts2phc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ts2phc.c b/ts2phc.c
index db5ea3f..3bbbbd3 100644
--- a/ts2phc.c
+++ b/ts2phc.c
@@ -577,6 +577,7 @@ int main(int argc, char *argv[])
                ts2phc_cleanup(&priv);
                return -1;
        }
+       priv.cfg = cfg;
        priv.agent = pmc_agent_create();
        if (!priv.agent) {
                ts2phc_cleanup(&priv);
@@ -662,7 +663,6 @@ int main(int argc, char *argv[])
        print_set_level(config_get_int(cfg, NULL, "logging_level"));
 
        STAILQ_INIT(&priv.sinks);
-       priv.cfg = cfg;
 
        snprintf(uds_local, sizeof(uds_local), "/var/run/ts2phc.%d",
                 getpid());
-- 
2.30.2



_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to