Q:

Properly release allocated virtual memory

I have been just wondering how much time it takes CPU to handle numerous NOP operations and somehow calculate total operations per second, so I came up with this code:
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <Windows.h>

int main(){
    printf("NOP watch\n");
    LPCH buffer=0;
    int count=0;
    while (true){
        int success=0;
        do {
            printf("NOP count: ");
            int success=scanf("%d", &count);
        } while (success);
        buffer = (LPCH)VirtualAlloc(0, count + 1, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        if (!buffer){
            printf("Not enough RAM available, code: %d!\n",GetLastError());
        }
        else {
            for (int i = 0; i < count; i++)
                buffer[i] = '\x90';
            buffer[count] = 0xC3;
            clock_t start = clock();
            ((void(*)())buffer)();
            float t = (clock() - start) / (CLOCKS_PER_SEC * 1.0f);
            printf(" Time: %f, operations per second: %.3f M\n", t, (count / t) / 1e6);
            VirtualFree(buffer, count + 1, MEM_RELEASE);
            MEMORYSTATUSEX statex;
            statex.dwLength = sizeof(statex);
            GlobalMemoryStatusEx(&statex);
            printf("  Available virtual memory: %.2f/%.2f MB\n", statex.ullAvailVirtual / (1024.0f*1024.0f), statex.ullTotalVirtual / (1024.0f * 1024.0f));
        }
    }
}

I simply allocate count + 1 bytes of memory, write count NOPs there and RET, call the memory block, and release memory.
But somehow, VirtualFree(buffer, count + 1, MEM_RELEASE) doesn't release absolutely anything and I run out of memory quickly. Where is the mistake?
Here is example output:
NOP count: 500000000
 Time: 0.086000, operations per second: 5813.954 M
  Available virtual memory: 1558.46/2047.88 MB
NOP count: 500000000
 Time: 0.094000, operations per second: 5319.149 M
  Available virtual memory: 1081.62/2047.88 MB
NOP count: 500000000
 Time: 0.105000, operations per second: 4761.905 M
  Available virtual memory: 604.78/2047.88 MB
NOP count: 500000000
Not enough RAM available, code: 8!

A:

I am not sure about the details, but the documentation https://msdn.microsoft.com/en-us/library/windows/desktop/aa366892%28v=vs.85%29.aspx states that the second parameter for VirtualFree should be zero if the third parameter is MEM_RELEASE.

