HeapAlloc vs. malloc. How does HeapAlloc work?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I am little bit interested in Wine source code. There is one thing I don't understand. How does HeapAlloc() work? Is it the same behavior as Winapi HeapAlloc()? If so then I have to check NULL value after each calling of this function, don't I?

I have found this code in Wine 0.9.57:

In dlls/dbghelp/stabs.c function 'static int stabs_new_include(const char* file, unsigned long val)' line 163:

        if (!include_defs)
            include_defs = HeapAlloc(GetProcessHeap(), 0, 
                                     sizeof(include_defs[0]) * num_alloc_include_def);
        else
            include_defs = HeapReAlloc(GetProcessHeap(), 0, include_defs,
                                       sizeof(include_defs[0]) * num_alloc_include_def);
        memset(include_defs + num_include_def, 0, sizeof(include_defs[0]) * 256);
    }
    include_defs[num_include_def].name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(file) + 1), file);
    include_defs[num_include_def].value = val;
    include_defs[num_include_def].vector = NULL;
    include_defs[num_include_def].nrofentries = 0;

Nobody is checking NULL value of include_defs and later there is strcpy() with HeapAlloc as parameter.

In dlls/winspool.drv/info.c function 'static LPDEVMODEA DEVMODEdupWtoA(HANDLE heap, const DEVMODEW *dmW)' line 1709

     if (pName) {
         len = MultiByteToWideChar(CP_ACP, 0, pName, -1, NULL, 0);
        nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
         MultiByteToWideChar(CP_ACP, 0, pName, -1, nameW, len);
     }

Again nobody is checking the nameW value. Maybe it is checked inside 'MultiByteToWideChar()' but this function doesn't return any value in this case.

There are places where value returned by HeapAlloc() is checked:

In dlls/wininet/internet.h 'static inline LPWSTR WININET_strdupW( LPCWSTR str )' line 82:

    LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
    if (ret) strcpyW( ret, str );
    return ret;

Could somebody explain me the behavior of Wine HeapAlloc() and its family?

Thank you,
cunha





[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux