function called multiple times causes program to exit with enigmatic error
===

I isolated the problem to this code:

    #include <windows.h>
    using namespace std;

    const wchar_t* readLine(int posX, int posY, int len) {
      wchar_t* wcharFromConsole = new wchar_t[len];
      COORD pos = {posX,posY};
      DWORD dwChars;
      ReadConsoleOutputCharacterW(GetStdHandle(STD_OUTPUT_HANDLE),
        wcharFromConsole,  // Buffer where store symbols
        len,     // Read len chars
        pos,    // Read from row=8, column=6
        &dwChars);  // How many symbols stored
      wcharFromConsole [dwChars] = L'\0'; // Terminate, so string functions can be used
      return wcharFromConsole;
    }

    int main() {
      for (int i = 0; i <= 63; i++) {
        readLine(0,0,80);
      }
      system("pause");
    }

The thing is if the loop is running less than 63 times it works, if length of chars loaded from console is less than 80 it also works... I have no Idea what is happening here. Are there any resources I must explicitly close... but why, if a function closes it should close also all of its resources. But what is happening here I have no idea, the compiled program (without any error) exits before silently `system()` function. There were other error codes as I removed portions of code from my project, sometimes it was that program requested termination in a unusual way, at other times program hanged and stopped accept keyboard input.