Re: [PATCH 07/12] perf kvm: handle realloc failures

From: Arnaldo Carvalho de Melo
Date: Mon Oct 08 2012 - 16:19:58 EST


Em Mon, Oct 08, 2012 at 11:17:31AM -0600, David Ahern escreveu:
> Save previous pointer and free on failure.

<SNIP>

> + prev = event->vcpu;
> event->vcpu = realloc(event->vcpu,
> event->max_vcpu * sizeof(*event->vcpu));
> if (!event->vcpu) {
> + free(prev);
> pr_err("Not enough memory\n");

Unfamiliar way of doing it, usually we do it like:

vcpu = realloc(event->vcpu, event->max_vcpu * sizeof(*event->vcpu));

if (!vcpu) {
pr_err("Not enough memory\n");
return -1;
}

event->vcpu = vcpu;

I.e. we don't trow away the old value of event->vcpu.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/