[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1339706321-8802-4-git-send-email-jolsa@redhat.com>
Date: Thu, 14 Jun 2012 22:38:38 +0200
From: Jiri Olsa <jolsa@...hat.com>
To: acme@...hat.com, a.p.zijlstra@...llo.nl, mingo@...e.hu,
paulus@...ba.org, cjashfor@...ux.vnet.ibm.com, fweisbec@...il.com,
eranian@...gle.com
Cc: linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...hat.com>
Subject: [PATCH 3/6] perf, tool: Properly free format data
Release format data in case there's failure during PMU load.
Format data are allocated during PMU lookup. If the lookup
fails in next steps, we dont release the format data.
Signed-off-by: Jiri Olsa <jolsa@...hat.com>
---
tools/perf/util/pmu.c | 50 +++++++++++++++++++++++++++++++-----------------
1 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index bda0563..1d73131 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -15,6 +15,14 @@ extern FILE *perf_pmu_in;
static LIST_HEAD(pmus);
+static void pmu_format_release(struct list_head *head)
+{
+ struct perf_pmu__format *format, *h;
+
+ list_for_each_entry_safe(format, h, head, list)
+ free(format);
+}
+
/*
* Parse & process all the sysfs attributes located under
* the directory specified in 'dir' parameter.
@@ -120,27 +128,33 @@ static struct perf_pmu *pmu_lookup(char *name)
LIST_HEAD(format);
__u32 type;
- /*
- * The pmu data we store & need consists of the pmu
- * type value and format definitions. Load both right
- * now.
- */
- if (pmu_format(name, &format))
- return NULL;
+ do {
+ /*
+ * The pmu data we store & need consists of the pmu
+ * type value and format definitions. Load both right
+ * now.
+ */
+ if (pmu_format(name, &format))
+ break;
- if (pmu_type(name, &type))
- return NULL;
+ if (pmu_type(name, &type))
+ break;
- pmu = zalloc(sizeof(*pmu));
- if (!pmu)
- return NULL;
+ pmu = zalloc(sizeof(*pmu));
+ if (!pmu)
+ break;
- INIT_LIST_HEAD(&pmu->format);
- list_splice(&format, &pmu->format);
- pmu->name = strdup(name);
- pmu->type = type;
- list_add_tail(&pmu->list, &pmus);
- return pmu;
+ INIT_LIST_HEAD(&pmu->format);
+ list_splice(&format, &pmu->format);
+ pmu->name = strdup(name);
+ pmu->type = type;
+ list_add_tail(&pmu->list, &pmus);
+ return pmu;
+
+ } while (0);
+
+ pmu_format_release(&format);
+ return NULL;
}
static struct perf_pmu *pmu_find(char *name)
--
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists