Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few memory leaks caught by cppcheck #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Combo/Combo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PlatformToolset>v141_xp</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down Expand Up @@ -137,6 +138,9 @@
<SuppressStartupBanner>true</SuppressStartupBanner>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalOptions>/Gw %(AdditionalOptions)</AdditionalOptions>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -155,6 +159,7 @@
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<Manifest>
<AdditionalManifestFiles>..\Resource\PCMan.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
Expand Down
4 changes: 2 additions & 2 deletions DlgLayout/DlgLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void CDlgLayout::OnSize(int cx, int cy)
{
if (ptab->layout & DLA_LEFT) //left anchor
{
l = l;
//l = l;
r = l + w;
}
else // no horizontal anchors
Expand All @@ -113,7 +113,7 @@ void CDlgLayout::OnSize(int cx, int cy)
{
if (ptab->layout & DLA_TOP) //top anchor
{
t = t;
//t = t;
b = t + h;
}
else // no vertical anchors
Expand Down
7 changes: 4 additions & 3 deletions Lite/AutoUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ CAutoUpdater::ErrorType CAutoUpdater::CheckForUpdate()
download_update_dlg->DoModal();

//download_update_dlg->OnCancel();
LPDWORD lpExitCode = new unsigned long;
*lpExitCode = STILL_ACTIVE;
//LPDWORD lpExitCode = new unsigned long;
//*lpExitCode = STILL_ACTIVE;
//DWORD ExitCode = STILL_ACTIVE;
//while(*lpExitCode==STILL_ACTIVE)
//{
// GetExitCodeThread(controlThread->m_hThread,lpExitCode);
Expand Down Expand Up @@ -301,7 +302,7 @@ CString CAutoUpdater::GetFileVersion(LPCTSTR file)
version.Format(_T("%d.%d"), ver[0], ver[1]);
}

delete pData;
delete[] pData;
return version;
}
catch(...) {
Expand Down
2 changes: 1 addition & 1 deletion Lite/BBSHyperLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const char* CBBSHyperLink::FindHyperLink(const char *src, int &len) const
break;
}
}
len = int(pend) - int(plink);
len = int(pend - plink);
return plink;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Lite/Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ BOOL CClipboard::SetText(HWND owner, LPCTSTR str, int len)
{
LPSTR buf = (LPSTR)GlobalLock(hmem);
PLCID lcid = (PLCID)GlobalLock(hlocmem);
memcpy(buf, str, len + 1);
memcpy(buf, str, len);
buf[len] = '\0';
// FIXME: Big5 should not be hard-coded since we have GB2312 version.
*lcid = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), SORT_CHINESE_BIG5);
GlobalUnlock(hmem);
Expand Down
5 changes: 5 additions & 0 deletions Lite/Lite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PlatformToolset>v141_xp</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down Expand Up @@ -137,6 +138,9 @@
<SuppressStartupBanner>true</SuppressStartupBanner>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalOptions>/Gw %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -155,6 +159,7 @@
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<Manifest>
<AdditionalManifestFiles>..\Resource\PCMan.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
Expand Down
2 changes: 1 addition & 1 deletion Lite/TermView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ void CTermView::OnEditPastefile()
data[len] = 0;
file.Abort();
telnet->SendString(data);
delete data;
delete[] data;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Lite/TriggerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void SetTriggerItem(CTriggerItem& item, char* line, CAES& crypto)
char* dec_buf = new char[enc_len + 2];
memset(dec_buf, 0, enc_len + 2);
crypto.Decrypt(enc_buf, dec_buf, enc_len);
delete enc_buf;
delete[] enc_buf;
int dec_len = strlen(dec_buf);
char* ppasswd = dec_buf + dec_len + 1;
if (memcmp(LPCTSTR(AppConfig.passwd), ppasswd, AppConfig.passwd.GetLength()))
Expand Down Expand Up @@ -203,16 +203,16 @@ void CTriggerList::Save(CString& section)
char* enc_buf = new char[ dec_len ];
memset(enc_buf, 0, dec_len);
crypto.Encrypt(dec_buf, enc_buf, dec_len);
delete []dec_buf;
delete[] dec_buf;

int base64_len = Base64Encode((BYTE*)enc_buf, dec_len, NULL, 0);
char* base64 = new char[ base64_len + 1 ];
base64_len = Base64Encode((BYTE*)enc_buf, dec_len, (BYTE*)base64, base64_len);
base64[ base64_len ] = '\0';
delete []enc_buf;
delete[] enc_buf;

section += base64;
delete base64;
delete[] base64;
}
else
{
Expand Down
5 changes: 2 additions & 3 deletions Version_Set_Combo.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
chcp 65001
SET MajorVersion=9
SET MinorVersion=5
SET PatchLevel=0
Expand All @@ -13,5 +12,5 @@ SET ProductName="PCMan Combo\0"
SET InternalName="PCMan Combo\0"
SET OriginalFilename="PCMan.exe\0"
SET FileDescription="PCMan\0"
SET LegalCopyright="Copyright (C) 2001 - 2009 由 洪任諭及 Open PCMan Team 共同製作\0"
SET Comments="本軟體由洪任諭及 Open PCMan Team 共同製作."
SET LegalCopyright="Copyright (C) 2001 - 2009 �� �x���٤� Open PCMan Team �@�P�s�@\0"
SET Comments="���n��Ѭx���٤� Open PCMan Team �@�P�s�@."
4 changes: 2 additions & 2 deletions Version_Set_Lite.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ SET ProductName="PCMan\0"
SET InternalName="PCMan\0"
SET OriginalFilename="PCMan.exe\0"
SET FileDescription="PCMan\0"
SET LegalCopyright="Copyright (C) 2001 - 2009 由 洪任諭及 Open PCMan Team 共同製作\0"
SET Comments="本軟體由洪任諭及 Open PCMan Team 共同製作."
SET LegalCopyright="Copyright (C) 2001 - 2009 �� �x���٤� Open PCMan Team �@�P�s�@\0"
SET Comments="���n��Ѭx���٤� Open PCMan Team �@�P�s�@."
24 changes: 14 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
version: '{build}'
image: Visual Studio 2017
configuration: Release

init:
- ps: Set-WinSystemLocale zh-TW
- ps: Start-Sleep -s 5
- ps: Start-Sleep -s 10
- ps: Restart-Computer
- ps: Start-Sleep -s 5

install:
# update vcpkg
- cd "C:\Tools\vcpkg"
- git pull
- .\bootstrap-vcpkg.bat
- cd "%APPVEYOR_BUILD_FOLDER%"
- vcpkg remove --outdated --recurse
- vcpkg install libwebsockets

- cd "%APPVEYOR_BUILD_FOLDER%"
- ps: .\Scripts\BeforeBuild.ps1
clone_folder: C:\projects\pcman-windows
cache: c:\tools\vcpkg\installed\
build:
project: PCMan.sln
parallel: true
verbosity: minimal

build_script:
- call msbuild /m /p:Configuration=Release %APPVEYOR_BUILD_FOLDER%\PCMan.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"

after_build:
- ps: .\Scripts\DownloadNonFree.ps1
- ps: .\Scripts\AfterBuild.ps1

artifacts:
- path: Lite\Release\PCMan.zip
- path: Combo\Release\PCManCB.zip
- path: Release\PCMan.exe
- path: Release\PCManCB.exe

cache:
- c:\tools\vcpkg\installed\

deploy:
provider: GitHub
auth_token: $(github_auth_token)
Expand Down