fixed segmention fault
abort allocation after first malloc fail
This commit is contained in:
parent
b3fa94b0e0
commit
ae1af7a053
1 changed files with 9 additions and 5 deletions
|
@ -62,16 +62,20 @@ int main(int argc, char** argv)
|
|||
int i;
|
||||
for (i = 0; i < chunks; i++) {
|
||||
test[i] = malloc(size);
|
||||
if (!test)
|
||||
printf("malloc(%d)\tFAILED!\n", chunks * sizeof(void *));
|
||||
else
|
||||
if (test[i])
|
||||
printf("malloc(%d)\tCHUNK: %d START: %p END: %p\n", size, i, test[i], test[i] + size);
|
||||
else {
|
||||
printf("malloc(%d)\tFAILED! Abort allocation, start with freeing memory\n", size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// and release again
|
||||
for (i = 0; i < chunks; i++) {
|
||||
free(test[i]);
|
||||
printf("free(%p)\tCHUNK: %d\n", test[i], i);
|
||||
if (test[i]) {
|
||||
free(test[i]);
|
||||
printf("free(%p)\tCHUNK: %d\n", test[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
free(test);
|
||||
|
|
Loading…
Add table
Reference in a new issue