下面删除文件夹的程序会不会造成内存泄露?
BOOL DeleteDirectory(CString psDirName)
{
int res=PathFileExists(psDirName);
//如果文件夹存在,则删除
if(res!=0)
{
int nLength = strlen(psDirName);
char *NewPath = new char[nLength+2];
strcpy(NewPath,psDirName);
NewPath[nLength] = '\0';
NewPath[nLength+1] = '\0';
SHFILEOPSTRUCT FileOp;
ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
FileOp.fFlags = FOF_NOCONFIRMATION;
FileOp.hNameMappings = NULL;
FileOp.hwnd = NULL;
FileOp.lpszProgressTitle = NULL;
FileOp.pFrom = NewPath;
FileOp.pTo = NULL;
FileOp.wFunc = FO_DELETE;
return SHFileOperation(&FileOp) == 0;
}
else
{
return 1;
}
功能上是能实现文件夹的删除的,但是我想问一下这样删除的话会不会造成内存泄露,
应该怎么改进,谢谢!