Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdbool.h>
- #define TEST_SIZE 1000000
- int32_t *p1;
- int32_t *p2;
- int32_t *p3;
- void cleanup()
- {
- free(p1);
- free(p2);
- free(p3);
- }
- int main()
- {
- int32_t *p_loc_1;
- int32_t *p_loc_2;
- int32_t *p_loc_3;
- p_loc_1 = malloc( TEST_SIZE * sizeof *p_loc_1 );
- p_loc_2 = malloc( TEST_SIZE * sizeof *p_loc_2 );
- p_loc_3 = malloc( TEST_SIZE * sizeof *p_loc_3 );
- if ( !p_loc_1 || !p_loc_2 || !p_loc_3 )
- {
- printf( "Error: cannot allocate memory (1).\n" );
- free( p_loc_1 );
- free( p_loc_2 );
- free( p_loc_3 );
- return 1;
- }
- // ... code ...
- free( p_loc_1 );
- free( p_loc_2 );
- free( p_loc_3 );
- /**************************************************************/
- p1 = malloc( TEST_SIZE * sizeof *p1 );
- p2 = malloc( TEST_SIZE * sizeof *p2 );
- p3 = malloc( TEST_SIZE * sizeof *p3 );
- if ( !p1 || !p2 || !p3 )
- {
- printf( "Error: cannot allocate memory (2).\n" );
- cleanup();
- return 1;
- }
- // ... code ...
- cleanup();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment