aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorThomas Jarosch <thomas.jarosch@intra2net.com>2013-01-25 05:02:13 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-30 08:38:48 -0500
commit8eb44dd76ac994b020e5cfe72635c90d9e0ad995 (patch)
tree570c931f5745a43e8bac24b365c12692b81de3e7 /tools/perf/util
parent68c465ada54c730d653fc6fdc9dc0d5270b2de00 (diff)
perf sort: Use pclose() instead of fclose() on pipe stream
cppcheck message: [tools/perf/util/sort.c:277]: (error) Mismatching allocation and deallocation: fp Also fix descriptor leak on error and always initialize the "fp" variable. Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com> Link: http://lkml.kernel.org/r/1359112354.yZcisNZ4k0@storm Link: http://lkml.kernel.org/r/2266358.qvDXKLvJ67@storm Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/sort.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 7ad62393aa88..83336610faa9 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -249,7 +249,7 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
249 size_t size, 249 size_t size,
250 unsigned int width __maybe_unused) 250 unsigned int width __maybe_unused)
251{ 251{
252 FILE *fp; 252 FILE *fp = NULL;
253 char cmd[PATH_MAX + 2], *path = self->srcline, *nl; 253 char cmd[PATH_MAX + 2], *path = self->srcline, *nl;
254 size_t line_len; 254 size_t line_len;
255 255
@@ -270,7 +270,6 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
270 270
271 if (getline(&path, &line_len, fp) < 0 || !line_len) 271 if (getline(&path, &line_len, fp) < 0 || !line_len)
272 goto out_ip; 272 goto out_ip;
273 fclose(fp);
274 self->srcline = strdup(path); 273 self->srcline = strdup(path);
275 if (self->srcline == NULL) 274 if (self->srcline == NULL)
276 goto out_ip; 275 goto out_ip;
@@ -280,8 +279,12 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
280 *nl = '\0'; 279 *nl = '\0';
281 path = self->srcline; 280 path = self->srcline;
282out_path: 281out_path:
282 if (fp)
283 pclose(fp);
283 return repsep_snprintf(bf, size, "%s", path); 284 return repsep_snprintf(bf, size, "%s", path);
284out_ip: 285out_ip:
286 if (fp)
287 pclose(fp);
285 return repsep_snprintf(bf, size, "%-#*llx", BITS_PER_LONG / 4, self->ip); 288 return repsep_snprintf(bf, size, "%-#*llx", BITS_PER_LONG / 4, self->ip);
286} 289}
287 290