perf tools: Catch a few uncheck calloc/malloc's
authorChris Samuel <chris@csamuel.org>
Sat, 13 Nov 2010 02:35:06 +0000 (13:35 +1100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Dec 2010 14:52:35 +0000 (12:52 -0200)
There were a few stray calloc()'s and malloc()'s which were not having
their return values checked for success.

As the calling code either already coped with failure or didn't actually
care we just return -ENOMEM at that point.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Chris Samuel <chris@csamuel.org>
LKML-Reference: <4CDDF95A.1050400@csamuel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kmem.c
tools/perf/builtin-lock.c
tools/perf/builtin-sched.c
tools/perf/builtin-timechart.c
tools/perf/util/header.c

index d0a652e9c7081cceb22a1dbad86a75f603b146c5..c9620ff6496ff67bf36836913fa98154d1ef0726 100644 (file)
@@ -736,6 +736,9 @@ static int __cmd_record(int argc, const char **argv)
        rec_argc = ARRAY_SIZE(record_args) + argc - 1;
        rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
+       if (rec_argv == NULL)
+               return -ENOMEM;
+
        for (i = 0; i < ARRAY_SIZE(record_args); i++)
                rec_argv[i] = strdup(record_args[i]);
 
index 92d3da52a5cf2c41f7ff6bd5481fa8fc214a0efd..b41b4492b1cc491d7ab941cc3bd709a92b2b6f1e 100644 (file)
@@ -943,6 +943,9 @@ static int __cmd_record(int argc, const char **argv)
        rec_argc = ARRAY_SIZE(record_args) + argc - 1;
        rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
+       if (rec_argv == NULL)
+               return -ENOMEM;
+
        for (i = 0; i < ARRAY_SIZE(record_args); i++)
                rec_argv[i] = strdup(record_args[i]);
 
index 73d1e30b0fed790c165afae77c4822fb8ae55d62..c7753940aea043690ac3d0ed593777c1b143f233 100644 (file)
@@ -1860,6 +1860,9 @@ static int __cmd_record(int argc, const char **argv)
        rec_argc = ARRAY_SIZE(record_args) + argc - 1;
        rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
+       if (rec_argv)
+               return -ENOMEM;
+
        for (i = 0; i < ARRAY_SIZE(record_args); i++)
                rec_argv[i] = strdup(record_args[i]);
 
index 1f158dc03349ba9c52724a1d49954083e75c4f32..d2fc46103f834ae314b2d631f2ef265e8b203e0f 100644 (file)
@@ -989,6 +989,9 @@ static int __cmd_record(int argc, const char **argv)
        rec_argc = ARRAY_SIZE(record_args) + argc - 1;
        rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
+       if (rec_argv == NULL)
+               return -ENOMEM;
+
        for (i = 0; i < ARRAY_SIZE(record_args); i++)
                rec_argv[i] = strdup(record_args[i]);
 
index 073f0e1c7123501820a7243c2840664524c9edd2..76e949a59ea497529ad1f6ab1d5e8d4db486c6c4 100644 (file)
@@ -1005,6 +1005,9 @@ int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
 
        ev = malloc(size);
 
+       if (ev == NULL)
+               return -ENOMEM;
+
        ev->attr.attr = *attr;
        memcpy(ev->attr.id, id, ids * sizeof(u64));