mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 09:13:00 +00:00
[CMD] Create a DirNodeCleanup() helper for cleanup and simplify code (adapted from PR #592).
This commit is contained in:
parent
06504ee4be
commit
12517aa309
1 changed files with 26 additions and 53 deletions
|
@ -1314,6 +1314,27 @@ QsortFiles(PDIRFINDINFO ptrArray[], /* [IN/OUT] The array with file info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
DirNodeCleanup(PDIRFINDLISTNODE ptrStartNode,
|
||||||
|
PDWORD pdwCount)
|
||||||
|
{
|
||||||
|
PDIRFINDLISTNODE ptrNextNode;
|
||||||
|
PDIRFINDSTREAMNODE ptrFreeNode;
|
||||||
|
while (ptrStartNode)
|
||||||
|
{
|
||||||
|
ptrNextNode = ptrStartNode->ptrNext;
|
||||||
|
while (ptrStartNode->stInfo.ptrHead)
|
||||||
|
{
|
||||||
|
ptrFreeNode = ptrStartNode->stInfo.ptrHead;
|
||||||
|
ptrStartNode->stInfo.ptrHead = ptrFreeNode->ptrNext;
|
||||||
|
cmd_free(ptrFreeNode);
|
||||||
|
}
|
||||||
|
cmd_free(ptrStartNode);
|
||||||
|
ptrStartNode = ptrNextNode;
|
||||||
|
--(*pdwCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DirList
|
* DirList
|
||||||
*
|
*
|
||||||
|
@ -1341,7 +1362,6 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
||||||
WIN32_FIND_STREAM_DATA wfsdStreamInfo;
|
WIN32_FIND_STREAM_DATA wfsdStreamInfo;
|
||||||
PDIRFINDSTREAMNODE * ptrCurNode; /* The pointer to the first stream */
|
PDIRFINDSTREAMNODE * ptrCurNode; /* The pointer to the first stream */
|
||||||
PDIRFINDSTREAMNODE ptrFreeNode; /* The pointer used during cleanup */
|
|
||||||
static HANDLE (WINAPI *pFindFirstStreamW)(LPCWSTR, STREAM_INFO_LEVELS, LPVOID, DWORD);
|
static HANDLE (WINAPI *pFindFirstStreamW)(LPCWSTR, STREAM_INFO_LEVELS, LPVOID, DWORD);
|
||||||
static BOOL (WINAPI *pFindNextStreamW)(HANDLE, LPVOID);
|
static BOOL (WINAPI *pFindNextStreamW)(HANDLE, LPVOID);
|
||||||
|
|
||||||
|
@ -1404,19 +1424,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
if (ptrNextNode->ptrNext == NULL)
|
if (ptrNextNode->ptrNext == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
WARN("DEBUG: Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
||||||
while (ptrStartNode)
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
{
|
|
||||||
ptrNextNode = ptrStartNode->ptrNext;
|
|
||||||
while (ptrStartNode->stInfo.ptrHead)
|
|
||||||
{
|
|
||||||
ptrFreeNode = ptrStartNode->stInfo.ptrHead;
|
|
||||||
ptrStartNode->stInfo.ptrHead = ptrFreeNode->ptrNext;
|
|
||||||
cmd_free(ptrFreeNode);
|
|
||||||
}
|
|
||||||
cmd_free(ptrStartNode);
|
|
||||||
ptrStartNode = ptrNextNode;
|
|
||||||
dwCount--;
|
|
||||||
}
|
|
||||||
FindClose(hSearch);
|
FindClose(hSearch);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1466,19 +1474,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
if (*ptrCurNode == NULL)
|
if (*ptrCurNode == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for *ptrCurNode!\n");
|
WARN("DEBUG: Cannot allocate memory for *ptrCurNode!\n");
|
||||||
while (ptrStartNode)
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
{
|
|
||||||
ptrNextNode = ptrStartNode->ptrNext;
|
|
||||||
while (ptrStartNode->stInfo.ptrHead)
|
|
||||||
{
|
|
||||||
ptrFreeNode = ptrStartNode->stInfo.ptrHead;
|
|
||||||
ptrStartNode->stInfo.ptrHead = ptrFreeNode->ptrNext;
|
|
||||||
cmd_free(ptrFreeNode);
|
|
||||||
}
|
|
||||||
cmd_free(ptrStartNode);
|
|
||||||
ptrStartNode = ptrNextNode;
|
|
||||||
dwCount--;
|
|
||||||
}
|
|
||||||
FindClose(hStreams);
|
FindClose(hStreams);
|
||||||
FindClose(hSearch);
|
FindClose(hSearch);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1532,19 +1528,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
if (ptrFileArray == NULL)
|
if (ptrFileArray == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for ptrFileArray!\n");
|
WARN("DEBUG: Cannot allocate memory for ptrFileArray!\n");
|
||||||
while (ptrStartNode)
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
{
|
|
||||||
ptrNextNode = ptrStartNode->ptrNext;
|
|
||||||
while (ptrStartNode->stInfo.ptrHead)
|
|
||||||
{
|
|
||||||
ptrFreeNode = ptrStartNode->stInfo.ptrHead;
|
|
||||||
ptrStartNode->stInfo.ptrHead = ptrFreeNode->ptrNext;
|
|
||||||
cmd_free(ptrFreeNode);
|
|
||||||
}
|
|
||||||
cmd_free(ptrStartNode);
|
|
||||||
ptrStartNode = ptrNextNode;
|
|
||||||
dwCount --;
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1582,20 +1566,9 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
|
|
||||||
/* Free array */
|
/* Free array */
|
||||||
cmd_free(ptrFileArray);
|
cmd_free(ptrFileArray);
|
||||||
|
|
||||||
/* Free linked list */
|
/* Free linked list */
|
||||||
while (ptrStartNode)
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
{
|
|
||||||
ptrNextNode = ptrStartNode->ptrNext;
|
|
||||||
while (ptrStartNode->stInfo.ptrHead)
|
|
||||||
{
|
|
||||||
ptrFreeNode = ptrStartNode->stInfo.ptrHead;
|
|
||||||
ptrStartNode->stInfo.ptrHead = ptrFreeNode->ptrNext;
|
|
||||||
cmd_free(ptrFreeNode);
|
|
||||||
}
|
|
||||||
cmd_free(ptrStartNode);
|
|
||||||
ptrStartNode = ptrNextNode;
|
|
||||||
dwCount --;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckCtrlBreak(BREAK_INPUT))
|
if (CheckCtrlBreak(BREAK_INPUT))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue