[PATCH 3/4] powerpc: Add simple memory allocator to bootwrapper

David Gibson david at gibson.dropbear.id.au
Tue Oct 10 16:25:38 EST 2006


On Mon, Oct 09, 2006 at 11:12:46PM -0700, Mark A. Greer wrote:
> Provide primitive malloc, free, and realloc functions for bootwrapper.

[snip]
> +/*
> + * Change size of area pointed to by 'ptr' to 'size'.
> + * If 'ptr' is NULL, then its a malloc().  If 'size' is 0, then its a free().
> + * 'ptr' must be NULL or a value previously returned by simple_realloc().
> + */
> +static void *simple_realloc(void *ptr, unsigned long size)
> +{
> +	if (size == 0) {
> +		simple_free(ptr);
> +		return NULL;
> +	}
> +	else if (ptr == NULL)
> +		return simple_malloc(size);
> +	else {
> +		simple_free(ptr);
> +		return simple_malloc(size);
> +	}
> +}

Um.. the above is clearly broken, it will throw away the data in a
realloc()ed block.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson



More information about the Linuxppc-dev mailing list