I'm writing a CESetup.dll for a Windows Mobile app. It must be unmanaged, which I have little experience with. So I'm unsure of whether I should free the memory I allocate and how I do it.
Here's the function I've written:
Uninstall_Init(
HWND hwndParent,
LPCTSTR pszInstallDir
)
{
LPTSTR folderPath = new TCHAR[256];
_stprintf(folderPath, _T("%s\\cache"), pszInstallDir);
EmptyDirectory(folderPath);
RemoveDirectory(folderPath);
_stprintf(folderPath, _T("%s\\mobileadmin.dat"), pszInstallDir);
DeleteFile(folderPath);
// To continue uninstallation, return codeUNINSTALL_INIT_CONTINUE
// If you want to cancel installation,
// return codeUNINSTALL_INIT_CANCEL
return codeUNINSTALL_INIT_CONTINUE;
}
As I understand it, folderPath is allocated on the heap. EmptyDirectory() is my own function that removes all content in the directory. RemoveDirectory() and DeleteFile() are system calls.
My question is should I deallocate folderPath
before the function exits? If I should, how do I do it?