char **array;
array = malloc(bufsize * sizeof(char));
array[i] = line;
I think your problem is with array, you are indeed dynamically allocating memory for array but not array[i].
while ((getline(&line, &bufsize, fp)) != -1) {
array[i]=malloc(sizeof(char) * (bufsize+1));
printf("%s", line);
array[i] = line;
i++;
}
This should fix it
Edit after testing the program:
array = malloc(bufsize * sizeof(char));
should be
array = malloc(bufsize * sizeof(char*));