The first allocation is not correct. Rather than:
matriz1 = (int**) malloc(linhas_mat1 * sizeof(int));
It should be:
matriz1 = (int**) malloc(linhas_mat1 * sizeof(int*));
The exception message (8 bytes) seems to indicate a 64-bit application, so pointers would be 8 bytes while sizeof(int)
might only be 4 bytes. This would result in a memory overwrite while filling the array.