Discussion:
[Linuxptp-devel] [PATCH] phc2sys: free clock device when exit
Hangbin Liu
2017-06-22 14:36:33 UTC
Permalink
Since we called strdup() for clock device, we need free the memory
before exit.

Signed-off-by: Hangbin Liu <***@gmail.com>
---
phc2sys.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/phc2sys.c b/phc2sys.c
index 68db5af..41a9053 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -245,6 +245,16 @@ static struct clock *clock_add(struct node *node, char *device)
return c;
}

+static void clock_destroy(struct node *node)
+{
+ struct clock *c;
+
+ LIST_FOREACH(c, &node->clocks, list) {
+ if (c->device)
+ free(c->device);
+ }
+}
+
static struct port *port_get(struct node *node, unsigned int number)
{
struct port *p;
@@ -1544,6 +1554,7 @@ int main(int argc, char *argv[])
end:
if (node.pmc)
close_pmc(&node);
+ clock_destroy(&node);
config_destroy(cfg);
return r;
bad_usage:
--
2.5.5
Richard Cochran
2017-06-22 14:48:16 UTC
Permalink
Post by Hangbin Liu
+static void clock_destroy(struct node *node)
Can't we name this differently?

We already have a function called clock_destroy in clock.c. Yes, I
know that that is not linked into phc2sys, but for the sake of grep
and cscope we want unique names, please.

Thanks,
Richard
Hangbin Liu
2017-06-23 03:22:45 UTC
Permalink
Since we called strdup() for clock device, we need free the memory
before exit.

Signed-off-by: Hangbin Liu <***@gmail.com>
---
phc2sys.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/phc2sys.c b/phc2sys.c
index 68db5af..41a9053 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -245,6 +245,16 @@ static struct clock *clock_add(struct node *node, char *device)
return c;
}

+static void clock_cleanup(struct node *node)
+{
+ struct clock *c;
+
+ LIST_FOREACH(c, &node->clocks, list) {
+ if (c->device)
+ free(c->device);
+ }
+}
+
static struct port *port_get(struct node *node, unsigned int number)
{
struct port *p;
@@ -1544,6 +1554,7 @@ int main(int argc, char *argv[])
end:
if (node.pmc)
close_pmc(&node);
+ clock_cleanup(&node);
config_destroy(cfg);
return r;
bad_usage:
--
2.5.5
Richard Cochran
2017-06-23 05:33:14 UTC
Permalink
Post by Hangbin Liu
Since we called strdup() for clock device, we need free the memory
before exit.
Applied.

Thanks,
Richard

Loading...