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