[irqbalance] [PATCH 1/2] irqbalance: fixed memory leaks coming from non-freed strings

  • From: Petr Holasek <pholasek@xxxxxxxxxx>
  • To: irqbalance@xxxxxxxxxxxxx
  • Date: Thu, 19 Mar 2015 17:53:37 +0100

---
 cputree.c    | 2 ++
 irqbalance.c | 6 +++---
 irqbalance.h | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/cputree.c b/cputree.c
index 8ead034..e249da8 100644
--- a/cputree.c
+++ b/cputree.c
@@ -98,6 +98,7 @@ static void setup_banned_cpus(void)
  out:
        cpumask_scnprintf(buffer, 4096, banned_cpus);
        log(TO_CONSOLE, LOG_INFO, "Isolated CPUs: %s\n", buffer);
+       free(line);
 }
 
 static struct topo_obj* add_cache_domain_to_package(struct topo_obj *cache, 
@@ -344,6 +345,7 @@ static void dump_irq(struct irq_info *info, void *data)
        indent[i] = '\0';
        log(TO_CONSOLE, LOG_INFO, "%sInterrupt %i node_num is %d (%s/%u) \n", 
indent,
            info->irq, irq_numa_node(info)->number, classes[info->class], 
(unsigned int)info->load);
+       free(indent);
 }
 
 static void dump_balance_obj(struct topo_obj *d, void *data 
__attribute__((unused)))
diff --git a/irqbalance.c b/irqbalance.c
index 226fcc6..1ca3590 100644
--- a/irqbalance.c
+++ b/irqbalance.c
@@ -49,7 +49,7 @@ int numa_avail;
 int journal_logging = 0;
 int need_rescan;
 unsigned int log_mask = TO_ALL;
-char * log_indent;
+const char *log_indent;
 enum hp_e global_hint_policy = HINT_POLICY_IGNORE;
 unsigned long power_thresh = ULONG_MAX;
 unsigned long deepest_cache = 2;
@@ -289,9 +289,9 @@ int main(int argc, char** argv)
         * note that everything goes to the console before we check this
         */
        if (journal_logging)
-               log_indent = strdup("....");
+               log_indent = "....";
        else
-               log_indent = strdup("    ");
+               log_indent = "    ";
 
        if (!debug_mode)
                log_mask &= ~TO_CONSOLE;
diff --git a/irqbalance.h b/irqbalance.h
index a498dc2..1c6ec9e 100644
--- a/irqbalance.h
+++ b/irqbalance.h
@@ -140,7 +140,7 @@ static inline void for_each_object(GList *list, void 
(*cb)(struct topo_obj *obj,
 #define TO_CONSOLE     (1 << 1)
 #define TO_ALL         (TO_SYSLOG | TO_CONSOLE)
 
-extern char * log_indent;
+extern const char * log_indent;
 extern unsigned int log_mask;
 #ifdef HAVE_LIBSYSTEMD
 #define log(mask, lvl, fmt, args...) do {                                      
\
-- 
2.1.0


Other related posts:

  • » [irqbalance] [PATCH 1/2] irqbalance: fixed memory leaks coming from non-freed strings - Petr Holasek