I've written this code :
Code:
#define MAX_ALLOC 1000000
int number = 1;
void *ptr = NULL;
if (argc != 2){
controlled_exit( "you have to give 1 argument" );
}
if ( ( number = strtol( argv[1], NULL, 10 ) ) == 0 ){
controlled_exit("the argument must be over 0 and not a character");
}
else if ( number > MAX_ALLOC || number < 0 ){
controlled_exit("the argument must be over 0 and 1000000 or less");
}
printf("Program break: %p\n", sbrk(0));
if ( ( ptr = malloc(number) ) == NULL)
errxit("malloc");
printf("Program break (after malloc): %p\n", sbrk(0));
free(ptr);
printf("Program break (after free): %p\n", sbrk(0));
return EXIT_SUCCESS;
In the output, the program break before and after free(ptr) is the same. Did I do something wrong (In my book it says, after releasing a block on the top of the heap, the Program break will lower, when the free block at the top is large enough) or is one million bytes too small?