Revolved Deallocating a deallocated pointer: buf warning in archive.cpp.

This commit is contained in:
Matthew Budd 2020-06-15 21:58:13 -04:00
parent ce03bf18e7
commit 9eaad6e14d
1 changed files with 9 additions and 5 deletions

View File

@ -181,7 +181,7 @@ protected:
public:
explicit InStream()
: refCount(0)
: refCount(0), size(0)
{}
};
@ -374,17 +374,21 @@ void initArchiveSystem()
}
}
static std::string wstringFromPROPVARIANT(BSTR bstr, bool& success) {
static std::string wstringFromPROPVARIANT(BSTR bstr, bool& success)
{
std::string strret;
std::wstring tempfname = bstr;
int buflen = tempfname.size()*2;
char* buf = new char[buflen];
int ret = WideCharToMultiByte(CP_ACP,0,tempfname.c_str(),tempfname.size(),buf,buflen,0,0);
if(ret == 0) {
if (ret == 0)
{
delete[] buf;
success = false;
return strret;
}
buf[ret] = 0;
std::string strret = buf;
strret = buf;
delete[] buf;
success = true;
return strret;
@ -594,4 +598,4 @@ FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::str
FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename)
{
return FCEUD_OpenArchive(asr, fname, innerFilename, -1);
}
}