[Mesa-dev] [PATCH] i965: Use new/delete instead of realloc() in brw_ir_allocator.h
Francisco Jerez
currojerez at riseup.net
Wed Feb 11 08:57:14 PST 2015
Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com> writes:
> There is no error path available thus instead of giving
> realloc possibility to fail use new which will never
> return null pointer and throws bad_alloc on failure.
>
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
> src/mesa/drivers/dri/i965/brw_ir_allocator.h | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_ir_allocator.h b/src/mesa/drivers/dri/i965/brw_ir_allocator.h
> index b1237ed..5330bff 100644
> --- a/src/mesa/drivers/dri/i965/brw_ir_allocator.h
> +++ b/src/mesa/drivers/dri/i965/brw_ir_allocator.h
> @@ -40,8 +40,8 @@ namespace brw {
>
> ~simple_allocator()
> {
> - free(offsets);
> - free(sizes);
> + delete[] offsets;
> + delete[] sizes;
> }
>
> unsigned
> @@ -49,8 +49,16 @@ namespace brw {
> {
> if (capacity <= count) {
> capacity = MAX2(16, capacity * 2);
> - sizes = (unsigned *)realloc(sizes, capacity * sizeof(unsigned));
> - offsets = (unsigned *)realloc(offsets, capacity * sizeof(unsigned));
> +
> + unsigned *tmp_sizes = new unsigned[capacity];
> + memcpy(tmp_sizes, sizes, count * sizeof(unsigned));
> + delete[] sizes;
> + sizes = tmp_sizes;
> +
> + unsigned *tmp_offsets = new unsigned[capacity];
> + memcpy(tmp_offsets, offsets, count * sizeof(unsigned));
> + delete[] offsets;
> + offsets = tmp_offsets;
> }
>
> sizes[count] = size;
> --
> 1.8.5.1
Looks OK to me,
Reviewed-by: Francisco Jerez <currojerez at riseup.net>
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150211/81815f74/attachment.sig>
More information about the mesa-dev
mailing list