File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
lib/node_modules/@stdlib/math/strided/special/sabs2/benchmark/c Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -96,11 +96,16 @@ static float rand_float( void ) {
9696*/
9797static double benchmark ( int iterations , int len ) {
9898 double elapsed ;
99- float x [ len ] ;
100- float y [ len ] ;
99+ float * x = ( float * ) malloc ( len * sizeof ( float )) ;
100+ float * y = ( float * ) malloc ( len * sizeof ( float )) ;
101101 double t ;
102102 int i ;
103103
104+ if (x == NULL || y == NULL ) {
105+ printf ("Memory allocation failed.\n" );
106+ exit (1 );
107+ }
108+
104109 for ( i = 0 ; i < len ; i ++ ) {
105110 x [ i ] = ( rand_float ()* 200.0f ) - 100.0f ;
106111 y [ i ] = 0.0f ;
@@ -117,6 +122,11 @@ static double benchmark( int iterations, int len ) {
117122 if ( y [ 0 ] != y [ 0 ] ) {
118123 printf ( "should not return NaN\n" );
119124 }
125+
126+ // 🧹 Always clean up heap allocations
127+ free (x );
128+ free (y );
129+
120130 return elapsed ;
121131}
122132
You can’t perform that action at this time.
0 commit comments