The problem is this:
/*free each cell*/
int i;
for(i=0;i<getLength(p);i++){
free(p->digits[i]);
}
You don't want to free each cell, you want to free all of them at once. The above should be replaced with
free(p->digits);
Remember how you allocated the memory was:
huge->digits = malloc((sizeof(int))*length);
You didn't allocate a different pointer for each element of digits
, so no need to free every element separately.
If you are using unix/linux system, In terminal:
man 3 malloc
man 3 free
you will get more information about this.