Check the return code from malloc()
to make sure the array was actually allocated. I suspect that the following test would fail:
int *primeArray = (int*) malloc(numberOfPrimes * sizeof(int));
if (primeArray != NULL) { /* check that array was allocated */
for (i = 0; i < numberOfPrimes; ++i) {
primeArray[i] = 1;
}
}