Commit 57927858 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

cmd: Use standard C functions for memory allocation.

parent 702b92ad
......@@ -68,7 +68,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, BOOL called, WCHAR *startLabel, HA
prev_context = context;
context = LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT));
context -> h = h;
context->batchfileW = heap_strdupW(file);
context->batchfileW = xstrdupW(file);
context -> command = command;
memset(context -> shift_count, 0x00, sizeof(context -> shift_count));
context -> prev_context = prev_context;
......@@ -110,8 +110,8 @@ void WCMD_batch (WCHAR *file, WCHAR *command, BOOL called, WCHAR *startLabel, HA
* to the caller's caller.
*/
heap_free(context->batchfileW);
LocalFree (context);
free(context->batchfileW);
LocalFree(context);
if ((prev_context != NULL) && (!called)) {
WINE_TRACE("Batch completed, but was not 'called' so skipping outer batch too\n");
prev_context -> skip_rest = TRUE;
......@@ -256,7 +256,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
const char *p;
cp = GetOEMCP();
bufA = heap_xalloc(noChars);
bufA = xalloc(noChars);
/* Save current file position */
filepos.QuadPart = 0;
......@@ -264,7 +264,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
status = ReadFile(h, bufA, noChars, &charsRead, NULL);
if (!status || charsRead == 0) {
heap_free(bufA);
free(bufA);
return NULL;
}
......@@ -279,7 +279,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
SetFilePointerEx(h, filepos, NULL, FILE_BEGIN);
i = MultiByteToWideChar(cp, 0, bufA, p - bufA, buf, noChars);
heap_free(bufA);
free(bufA);
}
else {
if (!charsRead) return NULL;
......@@ -454,11 +454,11 @@ void WCMD_HandleTildeModifiers(WCHAR **start, BOOL atExecute)
size = GetEnvironmentVariableW(env, NULL, 0);
if (size > 0) {
WCHAR *fullpath = heap_xalloc(size * sizeof(WCHAR));
WCHAR *fullpath = malloc(size * sizeof(WCHAR));
if (!fullpath || (GetEnvironmentVariableW(env, fullpath, size) == 0) ||
(SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0))
size = 0;
heap_free(fullpath);
free(fullpath);
}
if (!size) {
......
......@@ -182,18 +182,18 @@ static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
ULONG domainLen = MAXSTRING;
SID_NAME_USE nameuse;
secBuffer = heap_xalloc(sizeNeeded * sizeof(BYTE));
secBuffer = xalloc(sizeNeeded * sizeof(BYTE));
/* Get the owners security descriptor */
if(!GetFileSecurityW(filename, OWNER_SECURITY_INFORMATION, secBuffer,
sizeNeeded, &sizeNeeded)) {
heap_free(secBuffer);
free(secBuffer);
return;
}
/* Get the SID from the SD */
if(!GetSecurityDescriptorOwner(secBuffer, &pSID, &defaulted)) {
heap_free(secBuffer);
free(secBuffer);
return;
}
......@@ -201,7 +201,7 @@ static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
if (LookupAccountSidW(NULL, pSID, name, &nameLen, domain, &domainLen, &nameuse)) {
swprintf(owner, ownerlen, L"%s%c%s", domain, '\\', name);
}
heap_free(secBuffer);
free(secBuffer);
}
return;
}
......@@ -242,7 +242,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
same directory. Note issuing a directory header with no contents
mirrors what windows does */
parms = inputparms;
fd = heap_xalloc(sizeof(WIN32_FIND_DATAW));
fd = xalloc(sizeof(WIN32_FIND_DATAW));
while (parms && lstrcmpW(inputparms->dirName, parms->dirName) == 0) {
concurrentDirs++;
......@@ -267,7 +267,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
if (tmpLen > widest) widest = tmpLen;
}
fd = HeapReAlloc(GetProcessHeap(),0,fd,(entry_count+1)*sizeof(WIN32_FIND_DATAW));
fd = realloc(fd, (entry_count + 1) * sizeof(WIN32_FIND_DATAW));
if (fd == NULL) {
FindClose (hff);
WINE_ERR("Out of memory\n");
......@@ -431,7 +431,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
}
}
}
heap_free(fd);
free(fd);
/* When recursing, look in all subdirectories for matches */
if (recurse) {
......@@ -466,13 +466,13 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(string));
/* Allocate memory, add to list */
thisDir = heap_xalloc(sizeof(DIRECTORY_STACK));
thisDir = xalloc(sizeof(DIRECTORY_STACK));
if (dirStack == NULL) dirStack = thisDir;
if (lastEntry != NULL) lastEntry->next = thisDir;
lastEntry = thisDir;
thisDir->next = NULL;
thisDir->dirName = heap_strdupW(string);
thisDir->fileName = heap_strdupW(parms->fileName);
thisDir->dirName = xstrdupW(string);
thisDir->fileName = xstrdupW(parms->fileName);
parms = parms->next;
}
}
......@@ -484,9 +484,9 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
dirStack = WCMD_list_directory (thisDir, 1);
while (thisDir != dirStack) {
DIRECTORY_STACK *tempDir = thisDir->next;
heap_free(thisDir->dirName);
heap_free(thisDir->fileName);
heap_free(thisDir);
free(thisDir->dirName);
free(thisDir->fileName);
free(thisDir);
thisDir = tempDir;
}
}
......@@ -786,7 +786,7 @@ void WCMD_directory (WCHAR *args)
}
WINE_TRACE("Using path '%s'\n", wine_dbgstr_w(path));
thisEntry = heap_xalloc(sizeof(DIRECTORY_STACK));
thisEntry = xalloc(sizeof(DIRECTORY_STACK));
if (fullParms == NULL) fullParms = thisEntry;
if (prevEntry != NULL) prevEntry->next = thisEntry;
prevEntry = thisEntry;
......@@ -798,11 +798,11 @@ void WCMD_directory (WCHAR *args)
wine_dbgstr_w(drive), wine_dbgstr_w(dir),
wine_dbgstr_w(fname), wine_dbgstr_w(ext));
thisEntry->dirName = heap_xalloc(sizeof(WCHAR) * (lstrlenW(drive)+lstrlenW(dir)+1));
thisEntry->dirName = xalloc(sizeof(WCHAR) * (wcslen(drive) + wcslen(dir) + 1));
lstrcpyW(thisEntry->dirName, drive);
lstrcatW(thisEntry->dirName, dir);
thisEntry->fileName = heap_xalloc(sizeof(WCHAR) * (lstrlenW(fname)+lstrlenW(ext)+1));
thisEntry->fileName = xalloc(sizeof(WCHAR) * (wcslen(fname) + wcslen(ext) + 1));
lstrcpyW(thisEntry->fileName, fname);
lstrcatW(thisEntry->fileName, ext);
......@@ -812,10 +812,10 @@ void WCMD_directory (WCHAR *args)
/* If just 'dir' entered, a '*' parameter is assumed */
if (fullParms == NULL) {
WINE_TRACE("Inserting default '*'\n");
fullParms = heap_xalloc(sizeof(DIRECTORY_STACK));
fullParms = xalloc(sizeof(DIRECTORY_STACK));
fullParms->next = NULL;
fullParms->dirName = heap_strdupW(cwd);
fullParms->fileName = heap_strdupW(L"*");
fullParms->dirName = xstrdupW(cwd);
fullParms->fileName = xstrdupW(L"*");
}
lastDrive = '?';
......@@ -872,8 +872,8 @@ exit:
while (fullParms != NULL) {
prevEntry = fullParms;
fullParms = prevEntry->next;
heap_free(prevEntry->dirName);
heap_free(prevEntry->fileName);
heap_free(prevEntry);
free(prevEntry->dirName);
free(prevEntry->fileName);
free(prevEntry);
}
}
......@@ -30,7 +30,6 @@
#include <stdio.h>
#include <ctype.h>
#include <wchar.h>
#include <wine/heap.h>
/* msdn specified max for Win XP */
#define MAXSTRING 8192
......@@ -125,9 +124,9 @@ void WCMD_free_commands(CMD_LIST *cmds);
void WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
CMD_LIST **cmdList, BOOL retrycall);
void *heap_xalloc(size_t);
void *xalloc(size_t) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(free) __WINE_MALLOC;
static inline WCHAR *heap_strdupW(const WCHAR *str)
static inline WCHAR *xstrdupW(const WCHAR *str)
{
WCHAR *ret = NULL;
......@@ -135,7 +134,7 @@ static inline WCHAR *heap_strdupW(const WCHAR *str)
size_t size;
size = (lstrlenW(str)+1)*sizeof(WCHAR);
ret = heap_xalloc(size);
ret = xalloc(size);
memcpy(ret, str, size);
}
......
......@@ -67,7 +67,7 @@ static char *get_file_buffer(void)
{
static char *output_bufA = NULL;
if (!output_bufA)
output_bufA = heap_xalloc(MAX_WRITECONSOLE_SIZE);
output_bufA = xalloc(MAX_WRITECONSOLE_SIZE);
return output_bufA;
}
......@@ -423,11 +423,11 @@ static void WCMD_show_prompt (BOOL newLine) {
WCMD_output_asis (out_string);
}
void *heap_xalloc(size_t size)
void *xalloc(size_t size)
{
void *ret;
ret = heap_alloc(size);
ret = malloc(size);
if(!ret) {
ERR("Out of memory\n");
ExitProcess(1);
......@@ -732,16 +732,16 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR startchar)
WCHAR *searchFor;
if (equalspos == NULL) return start+1;
s = heap_strdupW(endOfVar + 1);
s = xstrdupW(endOfVar + 1);
/* Null terminate both strings */
thisVar[lstrlenW(thisVar)-1] = 0x00;
*equalspos = 0x00;
/* Since we need to be case insensitive, copy the 2 buffers */
searchIn = heap_strdupW(thisVarContents);
searchIn = xstrdupW(thisVarContents);
CharUpperBuffW(searchIn, lstrlenW(thisVarContents));
searchFor = heap_strdupW(colonpos+1);
searchFor = xstrdupW(colonpos + 1);
CharUpperBuffW(searchFor, lstrlenW(colonpos+1));
/* Handle wildcard case */
......@@ -779,9 +779,9 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR startchar)
thisVarContents + (lastFound-searchIn));
lstrcatW(outputposn, s);
}
heap_free(s);
heap_free(searchIn);
heap_free(searchFor);
free(s);
free(searchIn);
free(searchFor);
}
return start;
}
......@@ -971,7 +971,7 @@ static void init_msvcrt_io_block(STARTUPINFOW* st)
* its new input & output handles)
*/
sz = max(sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * 3, st_p.cbReserved2);
ptr = heap_xalloc(sz);
ptr = xalloc(sz);
flags = (char*)(ptr + sizeof(unsigned));
handles = (HANDLE*)(flags + num * sizeof(char));
......@@ -1221,7 +1221,7 @@ void WCMD_run_program (WCHAR *command, BOOL called)
Note: Launching internal wine processes cannot specify a full path to exe */
status = CreateProcessW(thisDir,
command, NULL, NULL, TRUE, 0, NULL, NULL, &st, &pe);
heap_free(st.lpReserved2);
free(st.lpReserved2);
if ((opt_c || opt_k) && !opt_s && !status
&& GetLastError()==ERROR_FILE_NOT_FOUND && command[0]=='\"') {
/* strip first and last quote WCHARacters and try again */
......@@ -1301,12 +1301,12 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
wine_dbgstr_w(command), cmdList);
/* Move copy of the command onto the heap so it can be expanded */
new_cmd = heap_xalloc(MAXSTRING * sizeof(WCHAR));
new_cmd = xalloc(MAXSTRING * sizeof(WCHAR));
lstrcpyW(new_cmd, command);
cmd = new_cmd;
/* Move copy of the redirects onto the heap so it can be expanded */
new_redir = heap_xalloc(MAXSTRING * sizeof(WCHAR));
new_redir = xalloc(MAXSTRING * sizeof(WCHAR));
redir = new_redir;
/* Strip leading whitespaces, and a '@' if supplied */
......@@ -1389,8 +1389,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
WINE_TRACE("Got directory %s as %s\n", wine_dbgstr_w(envvar), wine_dbgstr_w(cmd));
status = SetCurrentDirectoryW(cmd);
if (!status) WCMD_print_error ();
heap_free(cmd );
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
......@@ -1412,8 +1412,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
SetStdHandle (STD_INPUT_HANDLE, h);
......@@ -1427,8 +1427,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
&sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
SetStdHandle (STD_INPUT_HANDLE, h);
......@@ -1472,8 +1472,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
&sa, creationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
if (SetFilePointer (h, 0, NULL, FILE_END) ==
......@@ -1643,8 +1643,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
WCMD_run_program (whichcmd, FALSE);
echo_mode = prev_echo_mode;
}
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
/* Restore old handles */
for (i=0; i<3; i++) {
......@@ -1705,16 +1705,16 @@ static void WCMD_addCommand(WCHAR *command, int *commandLen,
CMD_LIST *thisEntry = NULL;
/* Allocate storage for command */
thisEntry = heap_xalloc(sizeof(CMD_LIST));
thisEntry = xalloc(sizeof(CMD_LIST));
/* Copy in the command */
if (command) {
thisEntry->command = heap_xalloc((*commandLen+1) * sizeof(WCHAR));
thisEntry->command = xalloc((*commandLen + 1) * sizeof(WCHAR));
memcpy(thisEntry->command, command, *commandLen * sizeof(WCHAR));
thisEntry->command[*commandLen] = 0x00;
/* Copy in the redirects */
thisEntry->redirects = heap_xalloc((*redirLen+1) * sizeof(WCHAR));
thisEntry->redirects = xalloc((*redirLen + 1) * sizeof(WCHAR));
memcpy(thisEntry->redirects, redirs, *redirLen * sizeof(WCHAR));
thisEntry->redirects[*redirLen] = 0x00;
thisEntry->pipeFile[0] = 0x00;
......@@ -1845,7 +1845,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
/* Allocate working space for a command read from keyboard, file etc */
if (!extraSpace)
extraSpace = heap_xalloc((MAXSTRING+1) * sizeof(WCHAR));
extraSpace = xalloc((MAXSTRING + 1) * sizeof(WCHAR));
if (!extraSpace)
{
WINE_ERR("Could not allocate memory for extraSpace\n");
......@@ -2399,9 +2399,9 @@ void WCMD_free_commands(CMD_LIST *cmds) {
while (cmds) {
CMD_LIST *thisCmd = cmds;
cmds = cmds->nextcommand;
heap_free(thisCmd->command);
heap_free(thisCmd->redirects);
heap_free(thisCmd);
free(thisCmd->command);
free(thisCmd->redirects);
free(thisCmd);
}
}
......@@ -2516,7 +2516,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
WCHAR *q1 = NULL,*q2 = NULL,*p;
/* Take a copy */
cmd = heap_strdupW(arg);
cmd = xstrdupW(arg);
/* opt_s left unflagged if the command starts with and contains exactly
* one quoted string (exactly two quote characters). The quoted string
......@@ -2674,7 +2674,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
WCMD_free_commands(toExecute);
toExecute = NULL;
heap_free(cmd);
free(cmd);
return errorlevel;
}
......@@ -2754,7 +2754,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
WCMD_process_commands(toExecute, FALSE, FALSE);
WCMD_free_commands(toExecute);
toExecute = NULL;
heap_free(cmd);
free(cmd);
}
/*
......
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