getting seg fault on malloc'ing for a string array. please help
#include<stdio.h>  
------------------  
#include<stdlib.h>  
--------------------  
#include<string.h      
--------------------  

enum { buf = BUFSIZ };

char line[buf], **tab = NULL;

 int cur_buf, count_lineMax = -1, count_line = -1,
    i, j, k, l;

int main (int argc, char **argv) {

        FILE *file1;
        file1 = fopen(argv[1], "r");

        cur_buf = buf;

        /*printf("%d\n", cur_buf);*/


                while(fgets(line, cur_buf, file1) != NULL) {

                        i = strlen(line);

                        for(j=0;j<i;j++) {
                                if(line[j] == '\n') {
                                        count_lineMax++;
                                }
                                /*printf("%c", line[j]);*/
                        }

                }
                /*printf("%d\n", count_lineMax);*/

                rewind(file1);

                tab = malloc(count_lineMax);
                memset(tab, 0, count_lineMax);


                for(k=0;k<count_lineMax;k++) {
                        tab[k] = malloc(cur_buf+1);
                        memset(tab[k], 0, cur_buf+1);
                }

                        while(fgets(line, cur_buf, file1) != NULL) {
                                i = strlen(line);

                                for(j=0;j<i;j++) {
                                        if(line[j] == '\n') {
                                                count_line++;
                                        }
                                }
                        tab[count_line] = line;
                        printf("%s", tab[count_line]);
                        }
        return 0;
        for(l=0;l<count_lineMax;l++) {
                free(tab[l]);
        }

        free(tab);
        fclose(file1);
}
## Heading ##
getting seg fault on malloc'ing for a string array. please help
===

#include<stdio.h>  
------------------  
#include<stdlib.h>  
--------------------  
#include<string.h      
--------------------  

enum { buf = BUFSIZ };

char line[buf], **tab = NULL;

 int cur_buf, count_lineMax = -1, count_line = -1,
    i, j, k, l;

int main (int argc, char **argv) {

        FILE *file1;
        file1 = fopen(argv[1], "r");

        cur_buf = buf;

        /*printf("%d\n", cur_buf);*/


                while(fgets(line, cur_buf, file1) != NULL) {

                        i = strlen(line);

                        for(j=0;j<i;j++) {
                                if(line[j] == '\n') {
                                        count_lineMax++;
                                }
                                /*printf("%c", line[j]);*/
                        }

                }
                /*printf("%d\n", count_lineMax);*/

                rewind(file1);

                tab = malloc(count_lineMax);
                memset(tab, 0, count_lineMax);


                for(k=0;k<count_lineMax;k++) {
                        tab[k] = malloc(cur_buf+1);
                        memset(tab[k], 0, cur_buf+1);
                }

                        while(fgets(line, cur_buf, file1) != NULL) {
                                i = strlen(line);

                                for(j=0;j<i;j++) {
                                        if(line[j] == '\n') {
                                                count_line++;
                                        }
                                }
                        tab[count_line] = line;
                        printf("%s", tab[count_line]);
                        }
        return 0;
        for(l=0;l<count_lineMax;l++) {
                free(tab[l]);
        }

        free(tab);
        fclose(file1);
}
## Heading ##