fixed segmention fault

abort allocation after first malloc fail
This commit is contained in:
Steffen Vogel 2013-10-07 17:22:53 +02:00
parent b3fa94b0e0
commit ae1af7a053

View file

@ -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);