Does the code compile without errors and warnings? I Don't think so. Increasing the compiler warn level may help you finding some problems (Project settings with VC).
pData->URL[0] = 0 ;
This will initialize the first element of the array, but not the others. Possible soure for problems.
TempURL = StrDupA(pURL) ;
TempURL
is not defined (compiler error).
StrDup()
returns a pointer to allocated memory and must be freed later using
LocalFree()
. Without freeing, you have memory leaks.
pData->URL[dwIndex] = (PCHAR)TempURL ;
This generates a compiler warning, because
dwIndex
is not initialized. Your code will probably crash.
dwTotalNumberOfURL = dwIndex ;
dwTotalNumberOfURL
is not defined (compiler error). Not necessary. Can use
dwIndex
contains instead.
pData
is allocated but not freed. Another memory leak.
DownloadFile(pData->URL, pData->DestinationPath) ;
pData->URL
is an array of
PCHAR
pointers. You did not show the code for
DownloadFile()
but it may be expects a
PCHAR
rather
PCHAR*
. If it expects a
PCHAR*
it would be OK.
You should initialize dwIndex, fill your struct with NULL bytes, and free up memory at the end of your function:
DWORD dwIndex = 0;
pData = (PMAINDATA)malloc(sizeof(MAINDATA)) ;
ZeroMemory(pData, sizeof(MAINDATA));
...
pData->URL[dwIndex] = (PCHAR)StrDupA(pURL) ;
...
for (DWORD i = 0; i < dwIndex && pData->URL[dwIndex]; i++)
LocalFree(pData->URL[dwIndex]);
free(pData);
return 0;
I did not know if I found all. There are too many.