Commit 43f01a2f authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

winmm: Use CRT allocation functions.

parent 38111eb3
......@@ -286,7 +286,7 @@ LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2)
if (*ptr == '\0') ptr = NULL;
}
lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
lpDrv = malloc(sizeof(WINE_DRIVER));
if (lpDrv == NULL) {cause = "OOM"; goto exit;}
if ((hModule = LoadLibraryW(fn)) == 0) {cause = "Not a 32 bit lib"; goto exit;}
......@@ -329,7 +329,7 @@ LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2)
return lpDrv;
exit:
FreeLibrary(hModule);
HeapFree(GetProcessHeap(), 0, lpDrv);
free(lpDrv);
TRACE("Unable to load 32 bit module %s: %s\n", debugstr_w(fn), cause);
return NULL;
}
......@@ -351,7 +351,7 @@ HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lPara
if (lpDriverName)
{
len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
dn = malloc( len * sizeof(WCHAR) );
if (!dn) goto done;
MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
}
......@@ -359,7 +359,7 @@ HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lPara
if (lpSectionName)
{
len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
sn = malloc( len * sizeof(WCHAR) );
if (!sn) goto done;
MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
}
......@@ -367,8 +367,8 @@ HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lPara
ret = OpenDriver(dn, sn, lParam);
done:
HeapFree(GetProcessHeap(), 0, dn);
HeapFree(GetProcessHeap(), 0, sn);
free(dn);
free(sn);
return ret;
}
......@@ -439,11 +439,11 @@ LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0, 0);
DRIVER_RemoveFromList(lpDrv0);
FreeLibrary(lpDrv0->hModule);
HeapFree(GetProcessHeap(), 0, lpDrv0);
free(lpDrv0);
}
FreeLibrary(lpDrv->hModule);
HeapFree(GetProcessHeap(), 0, lpDrv);
free(lpDrv);
ret = TRUE;
}
else
......
......@@ -137,7 +137,7 @@ LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
TRACE("(%d, %04x, %p, %p, %p, %p)\n",
size, type, hndl, dwFlags, dwCallback, dwInstance);
mld = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
mld = calloc(1, size);
if (!mld) return NULL;
/* find an empty slot in MM_MLDrvs table */
......@@ -146,7 +146,7 @@ LPWINE_MLD MMDRV_Alloc(UINT size, UINT type, LPHANDLE hndl, DWORD* dwFlags,
if (i == ARRAY_SIZE(MM_MLDrvs)) {
/* the MM_MLDrvs table could be made growable in the future if needed */
ERR("Too many open drivers\n");
HeapFree(GetProcessHeap(), 0, mld);
free(mld);
return NULL;
}
MM_MLDrvs[i] = mld;
......@@ -179,7 +179,7 @@ void MMDRV_Free(HANDLE hndl, LPWINE_MLD mld)
UINT_PTR idx = (UINT_PTR)hndl & ~0x8000;
if (idx < ARRAY_SIZE(MM_MLDrvs)) {
MM_MLDrvs[idx] = NULL;
HeapFree(GetProcessHeap(), 0, mld);
free(mld);
return;
}
}
......@@ -372,14 +372,9 @@ static BOOL MMDRV_InitPerType(LPWINE_MM_DRIVER lpDrv, UINT type, UINT wMsg)
part->nIDMin, part->nIDMax, llTypes[type].wMaxId,
lpDrv->drvname, llTypes[type].typestr);
/* realloc translation table */
if (llTypes[type].lpMlds) {
mem = llTypes[type].lpMlds - 1;
mem = HeapReAlloc(GetProcessHeap(), 0, mem, sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1));
mem = llTypes[type].lpMlds ? llTypes[type].lpMlds - 1 : NULL;
mem = realloc(mem, sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1));
llTypes[type].lpMlds = mem + 1;
} else {
mem = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1));
llTypes[type].lpMlds = mem + 1;
}
/* re-build the translation table */
if (lpDrv->bIsMapper) {
......@@ -463,7 +458,7 @@ static BOOL MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
* I don't have any clue for PE drvs
*/
lpDrv->bIsMapper = bIsMapper;
lpDrv->drvname = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(drvRegName) + 1), drvRegName);
lpDrv->drvname = strdup(drvRegName);
/* Finish init and get the count of the devices */
i = 0;
......@@ -476,7 +471,7 @@ static BOOL MMDRV_Install(LPCSTR drvRegName, LPCSTR drvFileName, BOOL bIsMapper)
/* if all those func calls return FALSE, then the driver must be unloaded */
if (!i) {
CloseDriver(lpDrv->hDriver, 0, 0);
HeapFree(GetProcessHeap(), 0, lpDrv->drvname);
free(lpDrv->drvname);
WARN("Driver initialization failed\n");
return FALSE;
}
......@@ -535,12 +530,12 @@ static void MMDRV_Init(void)
size = WideCharToMultiByte(CP_ACP, 0, pv.pwszVal, -1,
NULL, 0, NULL, NULL);
drvA = HeapAlloc(GetProcessHeap(), 0, size);
drvA = malloc(size);
WideCharToMultiByte(CP_ACP, 0, pv.pwszVal, -1, drvA, size, NULL, NULL);
MMDRV_Install(drvA, drvA, FALSE);
HeapFree(GetProcessHeap(), 0, drvA);
free(drvA);
PropVariantClear(&pv);
MMDRV_Install("wavemapper", "msacm32.drv", TRUE);
......@@ -609,15 +604,15 @@ void MMDRV_Exit(void)
CloseDriver(MMDrvs[i].hDriver, 0, 0);
}
if (llTypes[MMDRV_AUX].lpMlds)
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_AUX].lpMlds - 1);
free(llTypes[MMDRV_AUX].lpMlds - 1);
if (llTypes[MMDRV_MIXER].lpMlds)
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIXER].lpMlds - 1);
free(llTypes[MMDRV_MIXER].lpMlds - 1);
if (llTypes[MMDRV_MIDIIN].lpMlds)
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIIN].lpMlds - 1);
free(llTypes[MMDRV_MIDIIN].lpMlds - 1);
if (llTypes[MMDRV_MIDIOUT].lpMlds)
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_MIDIOUT].lpMlds - 1);
free(llTypes[MMDRV_MIDIOUT].lpMlds - 1);
if (llTypes[MMDRV_WAVEIN].lpMlds)
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEIN].lpMlds - 1);
free(llTypes[MMDRV_WAVEIN].lpMlds - 1);
if (llTypes[MMDRV_WAVEOUT].lpMlds)
HeapFree(GetProcessHeap(), 0, llTypes[MMDRV_WAVEOUT].lpMlds - 1);
free(llTypes[MMDRV_WAVEOUT].lpMlds - 1);
}
......@@ -319,7 +319,7 @@ static LPMMIOPROC MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
switch (dwFlags & (MMIO_INSTALLPROC|MMIO_REMOVEPROC|MMIO_FINDPROC)) {
case MMIO_INSTALLPROC:
/* Create new entry for the IOProc list */
pListNode = HeapAlloc(GetProcessHeap(), 0, sizeof(*pListNode));
pListNode = malloc(sizeof(*pListNode));
if (pListNode) {
/* Fill in this node */
pListNode->fourCC = fccIOProc;
......@@ -369,7 +369,7 @@ static LPMMIOPROC MMIO_InstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
struct IOProcList* ptmpNode = *ppListNode;
lpProc = (*ppListNode)->pIOProc;
*ppListNode = (*ppListNode)->pNext;
HeapFree(GetProcessHeap(), 0, ptmpNode);
free(ptmpNode);
}
}
break;
......@@ -498,7 +498,7 @@ static LPWINE_MMIO MMIO_Create(void)
static WORD MMIO_counter = 0;
LPWINE_MMIO wm;
wm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MMIO));
wm = calloc(1, sizeof(WINE_MMIO));
if (wm) {
EnterCriticalSection(&WINMM_cs);
/* lookup next unallocated WORD handle, with a non NULL value */
......@@ -527,7 +527,7 @@ static BOOL MMIO_Destroy(LPWINE_MMIO wm)
/* ...and destroy */
if (*m) {
*m = (*m)->lpNext;
HeapFree(GetProcessHeap(), 0, wm);
free(wm);
wm = NULL;
}
LeaveCriticalSection(&WINMM_cs);
......@@ -600,7 +600,7 @@ static MMRESULT MMIO_SetBuffer(WINE_MMIO* wm, void* pchBuffer, LONG cchBuffer,
/* free previous buffer if allocated */
if (wm->info.dwFlags & MMIO_ALLOCBUF) {
HeapFree(GetProcessHeap(), 0, wm->info.pchBuffer);
free(wm->info.pchBuffer);
wm->info.pchBuffer = NULL;
wm->info.dwFlags &= ~MMIO_ALLOCBUF;
}
......@@ -608,7 +608,7 @@ static MMRESULT MMIO_SetBuffer(WINE_MMIO* wm, void* pchBuffer, LONG cchBuffer,
if (pchBuffer) {
wm->info.pchBuffer = pchBuffer;
} else if (cchBuffer) {
if (!(wm->info.pchBuffer = HeapAlloc(GetProcessHeap(), 0, cchBuffer)))
if (!(wm->info.pchBuffer = malloc(cchBuffer)))
return MMIOERR_OUTOFMEMORY;
wm->info.dwFlags |= MMIO_ALLOCBUF;
} else {
......@@ -722,7 +722,7 @@ static HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo, DWORD dwOpenFlags,
return wm->info.hmmio;
error1:
if (wm->info.dwFlags & MMIO_ALLOCBUF)
HeapFree(GetProcessHeap(), 0, wm->info.pchBuffer);
free(wm->info.pchBuffer);
if (wm->ioProc) wm->ioProc->count--;
error2:
MMIO_Destroy(wm);
......@@ -742,14 +742,14 @@ HMMIO WINAPI mmioOpenW(LPWSTR szFileName, MMIOINFO* lpmmioinfo,
{
INT len = WideCharToMultiByte( CP_ACP, 0, szFileName, -1, NULL, 0, NULL, NULL );
if (len < MAX_PATH) len = MAX_PATH;
szFn = HeapAlloc( GetProcessHeap(), 0, len );
szFn = malloc( len );
if (!szFn) return NULL;
WideCharToMultiByte( CP_ACP, 0, szFileName, -1, szFn, len, NULL, NULL );
}
ret = MMIO_Open(szFn, lpmmioinfo, dwOpenFlags, TRUE);
HeapFree(GetProcessHeap(), 0, szFn);
free(szFn);
return ret;
}
......@@ -1401,14 +1401,14 @@ MMRESULT WINAPI mmioRenameW(LPCWSTR szFileName, LPCWSTR szNewFileName,
if (szFileName)
{
len = WideCharToMultiByte( CP_ACP, 0, szFileName, -1, NULL, 0, NULL, NULL );
szFn = HeapAlloc( GetProcessHeap(), 0, len );
szFn = malloc( len );
if (!szFn) goto done;
WideCharToMultiByte( CP_ACP, 0, szFileName, -1, szFn, len, NULL, NULL );
}
if (szNewFileName)
{
len = WideCharToMultiByte( CP_ACP, 0, szNewFileName, -1, NULL, 0, NULL, NULL );
sznFn = HeapAlloc( GetProcessHeap(), 0, len );
sznFn = malloc( len );
if (!sznFn) goto done;
WideCharToMultiByte( CP_ACP, 0, szNewFileName, -1, sznFn, len, NULL, NULL );
}
......@@ -1416,7 +1416,7 @@ MMRESULT WINAPI mmioRenameW(LPCWSTR szFileName, LPCWSTR szNewFileName,
ret = mmioRenameA(szFn, sznFn, lpmmioinfo, dwFlags);
done:
HeapFree(GetProcessHeap(),0,szFn);
HeapFree(GetProcessHeap(),0,sznFn);
free(szFn);
free(sznFn);
return ret;
}
......@@ -201,8 +201,8 @@ static void PlaySound_Free(WINE_PLAYSOUND* wps)
PlaySoundCurrent = NULL;
SetEvent(psLastEvent);
LeaveCriticalSection(&WINMM_cs);
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
HeapFree(GetProcessHeap(), 0, wps);
if (wps->bAlloc) free((void*)wps->pszSound);
free(wps);
}
static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
......@@ -210,7 +210,7 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
{
WINE_PLAYSOUND* wps;
wps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wps));
wps = calloc(1, sizeof(*wps));
if (!wps) return NULL;
wps->hMod = hmod;
......@@ -221,10 +221,8 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
{
if (fdwSound & SND_ASYNC)
{
LPWSTR sound = HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(pszSound)+1) * sizeof(WCHAR));
if (!sound) goto oom_error;
wps->pszSound = lstrcpyW(sound, pszSound);
wps->pszSound = wcsdup(pszSound);
if (!wps->pszSound) goto oom_error;
wps->bAlloc = TRUE;
}
else
......@@ -244,8 +242,8 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
return wps;
oom_error:
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
HeapFree(GetProcessHeap(), 0, wps);
if (wps->bAlloc) free((void*)wps->pszSound);
free(wps);
return NULL;
}
......@@ -359,7 +357,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
TRACE("Chunk Found ckid=%.4s fccType=%08lx cksize=%08lX\n",
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
lpWaveFormat = malloc(mmckInfo.cksize);
if (!lpWaveFormat)
goto errCleanUp;
r = mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize);
......@@ -394,7 +392,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
/* make it so that 3 buffers per second are needed */
bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
lpWaveFormat->nBlockAlign;
waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
waveHdr = malloc(2 * sizeof(WAVEHDR) + 2 * bufsize);
if (!waveHdr)
goto errCleanUp;
waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
......@@ -448,7 +446,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
errCleanUp:
TRACE("Done playing=%s => %s!\n", debugstr_w(wps->pszSound), bRet ? "ok" : "ko");
HeapFree(GetProcessHeap(), 0, lpWaveFormat);
free(lpWaveFormat);
if (hWave)
{
EnterCriticalSection(&WINMM_cs);
......@@ -459,7 +457,7 @@ errCleanUp:
Sleep(100);
}
CloseHandle(s.hEvent);
HeapFree(GetProcessHeap(), 0, waveHdr);
free(waveHdr);
if (hmmio) mmioClose(hmmio, 0);
PlaySound_Free(wps);
......
......@@ -349,14 +349,14 @@ UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
else if (uSize == 0) ret = MMSYSERR_NOERROR;
else
{
LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
WCHAR *xstr = malloc(uSize * sizeof(WCHAR));
if (!xstr) ret = MMSYSERR_NOMEM;
else
{
ret = midiOutGetErrorTextW(uError, xstr, uSize);
if (ret == MMSYSERR_NOERROR)
WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
HeapFree(GetProcessHeap(), 0, xstr);
free(xstr);
}
}
return ret;
......@@ -957,7 +957,7 @@ static WINE_MIDIStream *wine_midi_stream_allocate(void)
stream_id++;
if (stream_id < 0xFFFFFFFF &&
(stream = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream))))
(stream = malloc(sizeof(WINE_MIDIStream))))
{
stream->dwStreamID = stream_id;
wine_rb_put(&wine_midi_streams, &stream_id, &stream->entry);
......@@ -972,7 +972,7 @@ static void wine_midi_stream_free(WINE_MIDIStream *stream)
EnterCriticalSection(&WINMM_cs);
wine_rb_remove(&wine_midi_streams, &stream->entry);
HeapFree(GetProcessHeap(), 0, stream);
free(stream);
LeaveCriticalSection(&WINMM_cs);
}
......@@ -1392,7 +1392,7 @@ MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
mosm.wDeviceID = *lpuDeviceID;
lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm);
if (!lpwm) {
HeapFree(GetProcessHeap(), 0, lpMidiStrm);
free(lpMidiStrm);
return MMSYSERR_NOMEM;
}
lpMidiStrm->hDevice = hMidiOut;
......@@ -1404,7 +1404,7 @@ MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD_PTR)&lpwm->mod, CALLBACK_NULL);
if (ret != MMSYSERR_NOERROR) {
MMDRV_Free(hMidiOut, &lpwm->mld);
HeapFree(GetProcessHeap(), 0, lpMidiStrm);
free(lpMidiStrm);
return ret;
}
......@@ -1682,7 +1682,7 @@ static DWORD WINAPI mmTaskRun(void* pmt)
struct mm_starter mms;
memcpy(&mms, pmt, sizeof(struct mm_starter));
HeapFree(GetProcessHeap(), 0, pmt);
free(pmt);
mms.cb(mms.client);
if (mms.event) SetEvent(mms.event);
return 0;
......@@ -1697,7 +1697,7 @@ UINT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD_PTR client)
HANDLE hEvent = 0;
struct mm_starter *mms;
mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
mms = malloc(sizeof(struct mm_starter));
if (mms == NULL) return TASKERR_OUTOFMEMORY;
mms->cb = cb;
......@@ -1707,7 +1707,7 @@ UINT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD_PTR client)
hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
if (!hThread) {
HeapFree(GetProcessHeap(), 0, mms);
free(mms);
if (hEvent) CloseHandle(hEvent);
return TASKERR_OUTOFMEMORY;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment