struct foo* fooArray= malloc(sizeof(*fooArray)*5);
when you allocate fooArray, you allocate ONE buffer of
size 5 times a struct foo. If you want to hold 5 struct foo's, you are good, but you don't have to malloc the array members:
struct foo* newFoo = fooArray
struct foo* newFoo2 = fooArray + 1;
struct foo* newFoo3 = &fooArray[2]; /* array notation */
..and you can only free them all at once
free(fooArray);
BUT...
If you want a set of 5 pointers The size is wrong,
and the data type on the left is wrong.
struct foo* fooArray= malloc(sizeof(*fooArray)*5);
should read:
struct foo** fooArray = malloc(sizeof(struct foo*) * 5);
It is a pointer to 5 pointers.
Then your array notation can work for allocation and freeing.
fooArray[0] = malloc(sizeof struct foo);
free(fooArray[0]);
BTW, if you want an "array" to grow and shrink dynamically, you don't wan't an array. you want a Single linked list
Just include a (struct foo*) pointer in struct foo and you can do away with fooArray.