Application Verifier and MapViewOfFile

  application-verifier, file, memory, windows

I just started using Application Verifier (10.0,x64) to debug some potential memory issues, but now I’m running into several strange issues that were never issues before.

For example, when I call MapViewOfFile() on files less than 400KB, I’m getting return value 8, which I believe is ERROR_NOT_ENOUGH_MEMORY. The specific file that throws the error appears to randomly change, and sometimes the error doesn’t get thrown at all. I’ve narrowed the Application Verifier option down to the HEAP checkbox under BASIC. This option must be enabled for the errors to be thrown. I’ve never encountered any issues with this related code before using Application Verifier.

Is this pointing to an issue with my code somewhere, or is this some type of incompatibility? That is the question I’m trying to answer.

Here is my function. I realize this small fragment doesn’t provide much detail, so let me know if you want to see something specific. I only use this function to map entire files. So far, all of the files that are throwing errors are texture PNG images. That is likely because all other files are tiny in comparison.

Bool streamMap::OpenHandles() // Opens file handles
{
    // verify
    _VE( FilePtr == null && Offset == 0 && HXFile == INVALID_HANDLE_VALUE, "Invalid starting state. File may already be open. Cannot open another file with the same file interface object" );

    // create the File handle
    // + note: CreateFile macro is undefined by Kestarda, so we use actual function CreateFileA
    HXFile = CreateFileA( FullPath,
                    GENERIC_READ,           // open for reading
                    FILE_SHARE_READ,        // share for reading
                    null,                   // no security 
                    OPEN_EXISTING,          // existing file only 
                    FILE_ATTRIBUTE_NORMAL,  // normal file 
                    null);                  // no attribute template

    // check for failure
    if( HXFile == INVALID_HANDLE_VALUE )
        return false;

    // create Mapping
    // + we use 0 for dwMaximumSizeHigh & dwMaximumSizeLow to specify the entire file (supplied by HXFile)
    HXMap = CreateFileMapping( HXFile, 0, PAGE_READONLY, 0, 0, null );
    if( HXMap == null )
    {
        // close the file handle and return false
        CloseHandle( HXFile );
        HXFile = INVALID_HANDLE_VALUE;
        return false;
    }

    // get map view of file
    FilePtr = reinterpret_cast<byte*>( MapViewOfFile( HXMap, FILE_MAP_READ,0,0,0 ) );
    if( FilePtr == null )
    {
        // close both handles and return false
        CloseHandle(HXMap);
        CloseHandle(HXFile);

        HXMap = null;
        HXFile = INVALID_HANDLE_VALUE;
        return false;
    }

    // success
    return true;
}

Is anyone familiar enough with Application Verifier (and its HEAP option) to help me figure out why this is happening?

Source: Windows Questions

LEAVE A COMMENT