forked from Imagelibrary/rtems
malloctest: Fix issue with use after free
Do not call realloc() with a previously freed pointer. Perform a successful reallocation.
This commit is contained in:
committed by
Amar Takhar
parent
7215a3051a
commit
eb4f544689
@@ -1543,6 +1543,7 @@ static void test_early_malloc( void )
|
|||||||
void *r;
|
void *r;
|
||||||
void *s;
|
void *s;
|
||||||
void *t;
|
void *t;
|
||||||
|
void *u;
|
||||||
|
|
||||||
p = malloc( 1 );
|
p = malloc( 1 );
|
||||||
rtems_test_assert( p != NULL );
|
rtems_test_assert( p != NULL );
|
||||||
@@ -1556,15 +1557,8 @@ static void test_early_malloc( void )
|
|||||||
|
|
||||||
free( q );
|
free( q );
|
||||||
|
|
||||||
/*
|
r = realloc( NULL, 128 );
|
||||||
* This was added to address the following warning.
|
rtems_test_assert( r != q );
|
||||||
* warning: pointer 'q' used after 'free'
|
|
||||||
*/
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wuse-after-free"
|
|
||||||
r = realloc( q, 128 );
|
|
||||||
rtems_test_assert( r == q );
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
|
|
||||||
s = malloc( 1 );
|
s = malloc( 1 );
|
||||||
rtems_test_assert( s != NULL );
|
rtems_test_assert( s != NULL );
|
||||||
@@ -1575,7 +1569,10 @@ static void test_early_malloc( void )
|
|||||||
rtems_test_assert( t != NULL );
|
rtems_test_assert( t != NULL );
|
||||||
rtems_test_assert( t != r );
|
rtems_test_assert( t != r );
|
||||||
|
|
||||||
free( t );
|
u = realloc( t, 384 );
|
||||||
|
rtems_test_assert( t == u );
|
||||||
|
|
||||||
|
free( u );
|
||||||
}
|
}
|
||||||
|
|
||||||
RTEMS_SYSINIT_ITEM(
|
RTEMS_SYSINIT_ITEM(
|
||||||
|
|||||||
Reference in New Issue
Block a user