mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +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
|
||||
*
|
||||
|
@ -1341,7 +1362,6 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
|||
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
||||
WIN32_FIND_STREAM_DATA wfsdStreamInfo;
|
||||
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 BOOL (WINAPI *pFindNextStreamW)(HANDLE, LPVOID);
|
||||
|
||||
|
@ -1404,19 +1424,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
|||
if (ptrNextNode->ptrNext == NULL)
|
||||
{
|
||||
WARN("DEBUG: Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
||||
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;
|
||||
dwCount--;
|
||||
}
|
||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||
FindClose(hSearch);
|
||||
return 1;
|
||||
}
|
||||
|
@ -1466,19 +1474,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
|||
if (*ptrCurNode == NULL)
|
||||
{
|
||||
WARN("DEBUG: Cannot allocate memory for *ptrCurNode!\n");
|
||||
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;
|
||||
dwCount--;
|
||||
}
|
||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||
FindClose(hStreams);
|
||||
FindClose(hSearch);
|
||||
return 1;
|
||||
|
@ -1532,19 +1528,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
|||
if (ptrFileArray == NULL)
|
||||
{
|
||||
WARN("DEBUG: Cannot allocate memory for ptrFileArray!\n");
|
||||
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;
|
||||
dwCount --;
|
||||
}
|
||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1582,20 +1566,9 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
|||
|
||||
/* Free array */
|
||||
cmd_free(ptrFileArray);
|
||||
|
||||
/* Free linked list */
|
||||
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;
|
||||
dwCount --;
|
||||
}
|
||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||
|
||||
if (CheckCtrlBreak(BREAK_INPUT))
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue