2D Array Malloc
>Below is a part of a longer code where malloc'ing for a 2D array is done. Could anyone tell if this is correct? If I introduce static values, the code works fine. Else, seg faults...

    enum { LEN = 1024*8 };

    char **ta`enter code here`b = NULL;
    int cur_LEN = LEN;
    int count_lineMax = 0;


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

        if(tab == NULL && count_lineMax) {
            printf("Mem_check\n");
            exit(1);
        }

    for(k=0;k<count_lineMax;k++) {
                tab[k] = malloc(cur_LEN*sizeof(*tab[k]));
                memset(tab[k], 0, cur_LEN*sizeof(*tab[k]));

                if(tab[k] == NULL) {
                        printf("Mem_check*\n");
                        exit(1);
                }
        }
    for(l=0;l<count_lineMax;l++) {
                free(tab[l]);
        }
        free(tab);
2D Array Malloc
===

>Below is a part of a longer code where malloc'ing for a 2D array is done. Could anyone tell if this is correct? If I introduce static values, the code works fine. Else, seg faults...

    enum { LEN = 1024*8 };

    char **ta`enter code here`b = NULL;
    int cur_LEN = LEN;
    int count_lineMax = 0;


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

        if(tab == NULL && count_lineMax) {
            printf("Mem_check\n");
            exit(1);
        }

    for(k=0;k<count_lineMax;k++) {
                tab[k] = malloc(cur_LEN*sizeof(*tab[k]));
                memset(tab[k], 0, cur_LEN*sizeof(*tab[k]));

                if(tab[k] == NULL) {
                        printf("Mem_check*\n");
                        exit(1);
                }
        }
    for(l=0;l<count_lineMax;l++) {
                free(tab[l]);
        }
        free(tab);