No, that's not correct. By definition realloc() will deallocate the old memory (unless it can't allocate enough new storage). What that means is that you absolutely should not free pArray the way you are in your example. It will have already been deallocated by realloc(). Your code is overly complex. You should use realloc() something like this:
Code:
#include <stdlib.h>
#include <assert.h>
int main(void)
{
void *p, *t;
p = malloc(50);
assert(p != NULL);
t = realloc(p, 5000);
if(t == NULL)
{
/* deal with insufficient memory condition.
* note that p is still valid at this point.
*/
}
else
{
/* allocation was successful, reassign p */
p = t;
}
/* do something with p */
free(p);
return 0;
}