Abort called error in Linux when providing a huge input in C : <p>I have written a program in C to find if a pattern exists inside another pattern. Both the patterns are 2-D character arrays. 
To explain further, please consider the below case.</p>

<p>Suppose pattern A is </p>

<pre><code>1234567890  
0987654321  
1111111111  
1111111111  
2222222222 
</code></pre>

<p>and pattern B is </p>

<pre><code>876543  
111111  
111111
</code></pre>

<p>In this case, pattern B exists inside pattern A. Starting from 2nd row and 3rd column.</p>

<p>Below is my code.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main()
{
    int t, T, R, C, r, c;
    char** arr;
    char ** pat;
    int i, j, x, y, m = 0, n = 0, count = 0, brk_flag = 0, brk_flag2 = 0, found = 0;

    freopen("C:\\test.txt", "r", stdin);

    scanf("%d", &amp;T);
    for (t = 0; t&lt;T; t++) {

        scanf("%d%d", &amp;R, &amp;C);
        arr = (char**)malloc(R * sizeof(char*));
        if (arr == NULL) {
            printf("Unable to allocate memory.");
            exit(1);
        }


        for (i = 0; i &lt; R; i++) {

            arr[i] = (char*)malloc(C * sizeof(char));
            scanf("%s", arr[i]);

        }

        scanf("%d%d", &amp;r, &amp;c);
        pat = (char**)malloc(r * sizeof(char*));
        if (pat == NULL) {
            printf("Unable to allocate memory.");
            exit(1);
        }

        for (i = 0; i &lt; r; i++) {

            pat[i] = (char*)malloc(c * sizeof(char));
            scanf("%s", pat[i]);

        }


        brk_flag2 = 0;
        found = 0;
        for (i = 0; i &lt; R; i++) {

            for (j = 0; j &lt; C; j++) {

                if (arr[i][j] == pat[0][0]) {

                    if (i + r &gt; R || j + c &gt; C)
                        continue;

                    x = 0;
                    y = 0;
                    brk_flag = 0;
                    for (m = i; m&lt; i + r; m++) {

                        y = 0;
                        for (n = j; n&lt; j + c; n++) {

                            if (arr[m][n] == pat[x][y]) {

                                count++;
                            }
                            else {

                                brk_flag = 1;
                                break;
                            }
                            y++;
                        }
                        if (brk_flag == 1)
                            break;
                        x++;

                    }

                    if (count == (r * c)) {

                        printf("YES\n");
                        brk_flag2 = 1;
                        found = 1;
                        break;

                    }
                    count = 0;
                }

                else
                    continue;

            }
            if (brk_flag2 == 1)
                break;

        }

        if (found == 0) {

            printf("NO\n");

        }

        /*
        for (i = 0; i &lt; R; i++) {

            free(arr[i]);

        }

        for (i = 0; i &lt; r; i++) {

            free(pat[i]);

        }
        */

    }
    return 0;
}
</code></pre>

<p>For a testcase with pattern A of size 1000 X 1000, this works fine on Windows. But on Linux, I get an error as "Abort called".</p>

<p>I am unable to find where I am doing it wrong. Any ideas on this this would be hugely appreciated. Thanks.</p>
