2012-05-15 08:40:43

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH 12/11] parse-events: Cleanup realloc use

Ping?

On Tue, 24 Apr 2012 10:29:44 +0900, Namhyung Kim wrote:
> The if branch is completely unnecessary since 'realloc' can
> handle NULL pointers for the first parameter.
>
> This patch is just an adoption of Ulrich Drepper's recent
> patch on perf tools.
>
> Cc: Ulrich Drepper <[email protected]>
> Signed-off-by: Namhyung Kim <[email protected]>
> ---
> parse-events.c | 8 ++------
> parse-filter.c | 24 ++++++++----------------
> 2 files changed, 10 insertions(+), 22 deletions(-)
>
> diff --git a/parse-events.c b/parse-events.c
> index 3ccedd9..9779298 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -627,12 +627,8 @@ static void add_event(struct pevent *pevent, struct event_format *event)
> {
> int i;
>
> - if (!pevent->events)
> - pevent->events = malloc_or_die(sizeof(event));
> - else
> - pevent->events =
> - realloc(pevent->events, sizeof(event) *
> - (pevent->nr_events + 1));
> + pevent->events = realloc(pevent->events, sizeof(event) *
> + (pevent->nr_events + 1));
> if (!pevent->events)
> die("Can not allocate events");
>
> diff --git a/parse-filter.c b/parse-filter.c
> index bc62f1f..79be550 100644
> --- a/parse-filter.c
> +++ b/parse-filter.c
> @@ -148,17 +148,11 @@ add_filter_type(struct event_filter *filter, int id)
> if (filter_type)
> return filter_type;
>
> - if (!filter->filters)
> - filter->event_filters =
> - malloc_or_die(sizeof(*filter->event_filters));
> - else {
> - filter->event_filters =
> - realloc(filter->event_filters,
> - sizeof(*filter->event_filters) *
> - (filter->filters + 1));
> - if (!filter->event_filters)
> - die("Could not allocate filter");
> - }
> + filter->event_filters = realloc(filter->event_filters,
> + sizeof(*filter->event_filters) *
> + (filter->filters + 1));
> + if (!filter->event_filters)
> + die("Could not allocate filter");
>
> for (i = 0; i < filter->filters; i++) {
> if (filter->event_filters[i].event_id > id)
> @@ -1481,7 +1475,7 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
> {
> struct filter_type *filter_type;
> int count = 0;
> - int *ids;
> + int *ids = NULL;
> int i;
>
> if (!filter->filters)
> @@ -1505,10 +1499,8 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
> default:
> break;
> }
> - if (count)
> - ids = realloc(ids, sizeof(*ids) * (count + 1));
> - else
> - ids = malloc(sizeof(*ids));
> +
> + ids = realloc(ids, sizeof(*ids) * (count + 1));
> if (!ids)
> die("Can't allocate ids");
> ids[count++] = filter_type->event_id;


2012-05-15 08:48:52

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 12/11] parse-events: Cleanup realloc use

On Tue, 2012-05-15 at 17:39 +0900, Namhyung Kim wrote:
> Ping?

The 12/11 fooled me ;-) I added 1-11 but as my email is not sorted
well, I stopped at 11/11 (thinking that was the last patch).

I'll take a look at this one.

Thanks,

-- Steve

2012-05-15 09:33:49

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH 12/11] parse-events: Cleanup realloc use

Hi,

On Tue, 15 May 2012 04:48:45 -0400, Steven Rostedt wrote:
> On Tue, 2012-05-15 at 17:39 +0900, Namhyung Kim wrote:
>> Ping?
>
> The 12/11 fooled me ;-) I added 1-11 but as my email is not sorted
> well, I stopped at 11/11 (thinking that was the last patch).
>

Sorry, it should be sent separately. I'll not do it again.


> I'll take a look at this one.
>

Thanks,
Namhyung