From: Keith Whitwell Date: Tue, 18 Mar 2008 13:10:51 +0000 (+0000) Subject: gallium: make REALLOC a bit more like realloc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35a1ec53a7728311de22124c14b93dbbdee2ce90;p=mesa.git gallium: make REALLOC a bit more like realloc --- diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h index ef36ce75f7d..c2e0f8c6a5d 100644 --- a/src/gallium/include/pipe/p_util.h +++ b/src/gallium/include/pipe/p_util.h @@ -88,14 +88,16 @@ FREE( void *ptr ) static INLINE void * REALLOC( void *old_ptr, unsigned old_size, unsigned new_size ) { - void *new_ptr; - if( new_size <= old_size ) { - return old_ptr; - } - new_ptr = MALLOC( new_size ); - if( new_ptr ) { - memcpy( new_ptr, old_ptr, old_size ); + void *new_ptr = NULL; + + if (new_size != 0) { + new_ptr = MALLOC( new_size ); + + if( new_ptr && old_ptr ) { + memcpy( new_ptr, old_ptr, old_size ); + } } + FREE( old_ptr ); return new_ptr; }