Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbar committed Nov 21, 2024
1 parent e816d06 commit eb7ecc1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 31 deletions.
20 changes: 0 additions & 20 deletions src/CaCommon/WixString.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,26 +400,6 @@ class CWixString
return hr;
}

// Remove characters from the left
void RemoveLeft(DWORD dwCount)
{
DWORD dwNewLen = 0;
DWORD i = 0;

if (dwCount >= StrLen())
{
Release();
return;
}

dwNewLen = StrLen() - dwCount;
for (i = 0; i < dwNewLen; ++i)
{
_pS[i] = _pS[i + dwCount];
}
_pS[i] = NULL;
}

#pragma region Tokenize

HRESULT Tokenize(LPCWSTR delimiters, LPCWSTR* firstToken)
Expand Down
4 changes: 2 additions & 2 deletions src/PanelSwCustomActions/FileEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ CFileEntry::CFileEntry(const CFileEntry& other)
}
}

CFileEntry::CFileEntry(CFileEntry&& other)
CFileEntry::CFileEntry(CFileEntry&& other) noexcept
{
_szPath.Attach(other._szPath.Detach());
_szParentPath.Attach(other._szParentPath.Detach());
Expand Down Expand Up @@ -178,7 +178,7 @@ CFileEntry& CFileEntry::operator=(CFileEntry& other)
return *this;
}

CFileEntry& CFileEntry::operator=(CFileEntry&& other)
CFileEntry& CFileEntry::operator=(CFileEntry&& other) noexcept
{
_szPath.Attach(other._szPath.Detach());
_szParentPath.Attach(other._szParentPath.Detach());
Expand Down
4 changes: 2 additions & 2 deletions src/PanelSwCustomActions/FileEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class CFileEntry
CFileEntry(LPCWSTR szPath);
CFileEntry(const WIN32_FIND_DATA& findData, LPCWSTR szBasePath);
CFileEntry(const CFileEntry& other);
CFileEntry(CFileEntry&& other);
CFileEntry(CFileEntry&& other) noexcept;
CFileEntry& operator=(CFileEntry& other);
CFileEntry& operator=(CFileEntry&& other);
CFileEntry& operator=(CFileEntry&& other) noexcept;

// Attribute tests
DWORD Attributes() const;
Expand Down
8 changes: 2 additions & 6 deletions src/PanelSwCustomActions/FileIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ CFileIterator::~CFileIterator()

void CFileIterator::Release()
{
if (_hFind != INVALID_HANDLE_VALUE)
{
::FindClose(_hFind);
_hFind = INVALID_HANDLE_VALUE;
}
ReleaseFileFindHandle(_hFind);
memset(&_findData, 0, sizeof(_findData));
_findData.dwFileAttributes = INVALID_FILE_ATTRIBUTES;
_szBasePath.Release();
Expand Down Expand Up @@ -55,7 +51,7 @@ CFileEntry CFileIterator::Find(LPCWSTR szBasePath, LPCWSTR szPattern, bool bRecu

// We're searching without filespec wildcard pattern so we can match subfolders
_hFind = ::FindFirstFile(szBasePattern, &_findData);
ExitOnInvalidHandleWithLastError(_hFind, _hrStatus, "Failed to find files in '%ls'");
ExitOnInvalidHandleWithLastError(_hFind, _hrStatus, "Failed to find files in '%ls'", szBasePath);

return ProcessFindData();

Expand Down
3 changes: 3 additions & 0 deletions src/PanelSwCustomActions/PanelSwCustomActions.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
<ClInclude Include="$(BuildFolder)\obj\$(Configuration)\Protobuf\obfuscatedString.pb.h">
<AutoGen>True</AutoGen>
</ClInclude>
<ClInclude Include="$(BuildFolder)\obj\$(Configuration)\Protobuf\reparsePointDetails.pb.h">
<AutoGen>True</AutoGen>
</ClInclude>
<ClInclude Include="TopShelfService.h" />
<ClInclude Include="Unzip.h" />
<ClInclude Include="XslTransform.h" />
Expand Down
3 changes: 2 additions & 1 deletion src/PanelSwCustomActions/ReparsePoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extern "C" UINT __stdcall RemoveReparseDataSched(MSIHANDLE hInstall)
if (longNameIdx < szFileName.StrLen())
{
CWixString szOrig(szFileName);
szFileName.RemoveLeft(longNameIdx + 1);
szFileName.Substring(longNameIdx + 1);
WcaLog(LOGLEVEL::LOGMSG_STANDARD, "RemoveFile/@FileName column contains a short and long file names '%ls'. Ignoring the short name and using '%ls' only", (LPCWSTR)szOrig, (LPCWSTR)szFileName);
}
}
Expand Down Expand Up @@ -480,6 +480,7 @@ HRESULT CReparsePoint::DeleteReparsePoint(LPCWSTR szPath, LPVOID pBuffer, DWORD

LExit:
ReleaseFile(hFile);
ReleaseMem(pCurrReparseData)

return hr;
}

0 comments on commit eb7ecc1

Please sign in to comment.