@@ -31,46 +31,52 @@ compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
31
31
}
32
32
33
33
static void
34
- malloc_vs_mallocx_malloc (void )
34
+ malloc_free (void )
35
35
{
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 );
38
43
}
39
44
40
45
static void
41
- malloc_vs_mallocx_mallocx (void )
46
+ mallocx_free (void )
42
47
{
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 );
45
54
}
46
55
47
56
TEST_BEGIN (test_malloc_vs_mallocx )
48
57
{
49
58
50
59
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 );
52
61
}
53
62
TEST_END
54
63
55
64
static 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 )
64
66
{
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 );
67
73
}
68
74
69
75
TEST_BEGIN (test_free_vs_dallocx )
70
76
{
71
77
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 );
74
80
}
75
81
TEST_END
76
82
0 commit comments