@@ -31,46 +31,52 @@ compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
3131}
3232
3333static void
34- malloc_vs_mallocx_malloc (void )
34+ malloc_free (void )
3535{
36-
37- free (malloc (1 ));
36+ /* The compiler can optimize away free(malloc(1))! */
37+ void * p = malloc (1 );
38+ if (p == NULL ) {
39+ test_fail ("Unexpected malloc() failure" );
40+ return ;
41+ }
42+ free (p );
3843}
3944
4045static void
41- malloc_vs_mallocx_mallocx (void )
46+ mallocx_free (void )
4247{
43-
44- free (mallocx (1 , 0 ));
48+ void * p = mallocx (1 , 0 );
49+ if (p == NULL ) {
50+ test_fail ("Unexpected mallocx() failure" );
51+ return ;
52+ }
53+ free (p );
4554}
4655
4756TEST_BEGIN (test_malloc_vs_mallocx )
4857{
4958
5059 compare_funcs (10 * 1000 * 1000 , 100 * 1000 * 1000 , "malloc" ,
51- malloc_vs_mallocx_malloc , "mallocx" , malloc_vs_mallocx_mallocx );
60+ malloc_free , "mallocx" , mallocx_free );
5261}
5362TEST_END
5463
5564static void
56- free_vs_dallocx_free (void )
57- {
58-
59- free (malloc (1 ));
60- }
61-
62- static void
63- free_vs_dallocx_dallocx (void )
65+ malloc_dallocx (void )
6466{
65-
66- dallocx (malloc (1 ), 0 );
67+ void * p = malloc (1 );
68+ if (p == NULL ) {
69+ test_fail ("Unexpected malloc() failure" );
70+ return ;
71+ }
72+ dallocx (p , 0 );
6773}
6874
6975TEST_BEGIN (test_free_vs_dallocx )
7076{
7177
72- compare_funcs (10 * 1000 * 1000 , 100 * 1000 * 1000 , "free" , free_vs_dallocx_free ,
73- "dallocx" , free_vs_dallocx_dallocx );
78+ compare_funcs (10 * 1000 * 1000 , 100 * 1000 * 1000 , "free" , malloc_free ,
79+ "dallocx" , malloc_dallocx );
7480}
7581TEST_END
7682
0 commit comments