[02/14] eal: log: free dynamic state on cleanup
diff mbox series

Message ID 20200104013341.19809-3-stephen@networkplumber.org
State Superseded, archived
Delegated to: David Marchand
Headers show
Series
  • cleanup resources on shutdown
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 4, 2020, 1:33 a.m. UTC
When rte_eal_cleanup is called, free all the memory
associated with dynamic log levels and types.

Fixes: c1b5fa94a46f ("eal: support dynamic log types")
Cc: olivier.matz@6wind.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/common/eal_common_log.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

David Marchand April 25, 2020, 4:26 p.m. UTC | #1
On Sat, Jan 4, 2020 at 2:34 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> When rte_eal_cleanup is called, free all the memory
> associated with dynamic log levels and types.
>
> Fixes: c1b5fa94a46f ("eal: support dynamic log types")
> Cc: olivier.matz@6wind.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/librte_eal/common/eal_common_log.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
> index 64d6e20947ed..7583bdc57619 100644
> --- a/lib/librte_eal/common/eal_common_log.c
> +++ b/lib/librte_eal/common/eal_common_log.c
> @@ -470,8 +471,23 @@ eal_log_set_default(FILE *default_log)
>  void
>  eal_log_cleanup(void)
>  {
> +       struct rte_eal_opt_loglevel *opt_ll, *tmp;
> +       size_t i;
> +
>         if (default_log_stream) {
>                 fclose(default_log_stream);
>                 default_log_stream = NULL;
>         }
> +
> +       TAILQ_FOREACH_SAFE(opt_ll, &opt_loglevel_list, next, tmp) {
> +               free(opt_ll->pattern);

In regexp case, we have a leak on the regexp buffer.
Fixed with:

+        if (opt_ll->pattern != NULL)
+            free(opt_ll->pattern);
+        else
+            regfree(&opt_ll->re_match);


> +               free(opt_ll);
> +       }
> +
> +       for (i = 0; i < rte_logs.dynamic_types_len; i++)
> +               free(rte_logs.dynamic_types[i].name);
> +
> +       rte_logs.dynamic_types_len = 0;
> +       free(rte_logs.dynamic_types);
> +       rte_logs.dynamic_types = NULL;
>  }
> --
> 2.20.1
>

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 64d6e20947ed..7583bdc57619 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -14,6 +14,7 @@ 
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_per_lcore.h>
+#include <rte_tailq.h>
 
 #include "eal_private.h"
 
@@ -54,7 +55,7 @@  struct log_cur_msg {
 };
 
 struct rte_log_dynamic_type {
-	const char *name;
+	char *name;
 	uint32_t loglevel;
 };
 
@@ -470,8 +471,23 @@  eal_log_set_default(FILE *default_log)
 void
 eal_log_cleanup(void)
 {
+	struct rte_eal_opt_loglevel *opt_ll, *tmp;
+	size_t i;
+
 	if (default_log_stream) {
 		fclose(default_log_stream);
 		default_log_stream = NULL;
 	}
+
+	TAILQ_FOREACH_SAFE(opt_ll, &opt_loglevel_list, next, tmp) {
+		free(opt_ll->pattern);
+		free(opt_ll);
+	}
+
+	for (i = 0; i < rte_logs.dynamic_types_len; i++)
+		free(rte_logs.dynamic_types[i].name);
+
+	rte_logs.dynamic_types_len = 0;
+	free(rte_logs.dynamic_types);
+	rte_logs.dynamic_types = NULL;
 }