diff options
author | jonasno <jonasno@users.sourceforge.net> | 2010-01-18 18:01:32 +0300 |
---|---|---|
committer | jonasno <jonasno@users.sourceforge.net> | 2010-01-18 18:01:32 +0300 |
commit | 6a31a3854b5b450d9fe03f745f7b143bc10a9298 (patch) | |
tree | e6de368c231a50333784497e7b400f7483c5429f /src | |
parent | 0907b8ffb47c74ba7f09c6243c3df4cd5567f605 (diff) |
Fixed memory leaks
Fixed possible buffer overflows
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1527 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src')
-rw-r--r-- | src/apps/mplayerc/PlayerCaptureDialog.cpp | 12 | ||||
-rw-r--r-- | src/apps/mplayerc/mplayerc.cpp | 23 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/apps/mplayerc/PlayerCaptureDialog.cpp b/src/apps/mplayerc/PlayerCaptureDialog.cpp index 2c8a91f3e..9a360e01c 100644 --- a/src/apps/mplayerc/PlayerCaptureDialog.cpp +++ b/src/apps/mplayerc/PlayerCaptureDialog.cpp @@ -47,7 +47,11 @@ static bool LoadMediaType(CStringW DisplayName, AM_MEDIA_TYPE** ppmt) UINT len;
if(AfxGetApp()->GetProfileBinary(_T("Capture\\") + CString(DisplayName), _T("MediaType"), &pData, &len))
{
- if(len != sizeof(AM_MEDIA_TYPE)) return(fRet);
+ if ( len != sizeof(AM_MEDIA_TYPE) )
+ {
+ delete [] pData;
+ return(fRet);
+ }
memcpy(*ppmt, pData, len);
delete [] pData;
@@ -58,7 +62,11 @@ static bool LoadMediaType(CStringW DisplayName, AM_MEDIA_TYPE** ppmt) if(AfxGetApp()->GetProfileBinary(_T("Capture\\") + CString(DisplayName), _T("Format"), &pData, &len))
{
- if(!len) return(fRet);
+ if ( !len )
+ {
+ delete [] pData;
+ return(fRet);
+ }
(*ppmt)->cbFormat = len;
(*ppmt)->pbFormat = (BYTE*)CoTaskMemAlloc(len);
memcpy((*ppmt)->pbFormat, pData, len);
diff --git a/src/apps/mplayerc/mplayerc.cpp b/src/apps/mplayerc/mplayerc.cpp index eeb4b5643..9c805b11c 100644 --- a/src/apps/mplayerc/mplayerc.cpp +++ b/src/apps/mplayerc/mplayerc.cpp @@ -2005,9 +2005,12 @@ void CMPlayerCApp::Settings::UpdateData(bool fSave) // Last Open Dir
f_lastOpenDir = pApp->GetProfileString(IDS_R_SETTINGS, IDS_RS_LAST_OPEN_DIR, _T("C:\\"));
- if(pApp->GetProfileBinary(IDS_R_SETTINGS, IDS_RS_FULLSCREENRES, &ptr, &len))
+ if ( pApp->GetProfileBinary(IDS_R_SETTINGS, IDS_RS_FULLSCREENRES, &ptr, &len) )
{
- memcpy(&AutoChangeFullscrRes, ptr, sizeof(AutoChangeFullscrRes));
+ if ( len == sizeof(AChFR) )
+ memcpy( &AutoChangeFullscrRes, ptr, sizeof(AChFR) );
+ else
+ AutoChangeFullscrRes.bEnabled = false;
delete [] ptr;
}
else
@@ -2022,9 +2025,12 @@ void CMPlayerCApp::Settings::UpdateData(bool fSave) AspectRatio.cx = pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_ASPECTRATIO_X, 0);
AspectRatio.cy = pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_ASPECTRATIO_Y, 0);
fKeepHistory = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_KEEPHISTORY, 1);
- if(pApp->GetProfileBinary(IDS_R_SETTINGS, IDS_RS_LASTWINDOWRECT, &ptr, &len))
+ if ( pApp->GetProfileBinary(IDS_R_SETTINGS, IDS_RS_LASTWINDOWRECT, &ptr, &len) )
{
- memcpy(&rcLastWindowPos, ptr, sizeof(rcLastWindowPos));
+ if ( len == sizeof(CRect) )
+ memcpy( &rcLastWindowPos, ptr, sizeof(CRect) );
+ else
+ fRememberWindowPos = false;
delete [] ptr;
}
else
@@ -2062,10 +2068,11 @@ void CMPlayerCApp::Settings::UpdateData(bool fSave) tAudioTimeShift = pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_AUDIOTIMESHIFT, 0);
fDownSampleTo441 = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_DOWNSAMPLETO441, 0);
fCustomChannelMapping = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_CUSTOMCHANNELMAPPING, 0);
- if(pApp->GetProfileBinary(IDS_R_SETTINGS, IDS_RS_SPEAKERTOCHANNELMAPPING, &ptr, &len))
+
+ BOOL bResult = pApp->GetProfileBinary( IDS_R_SETTINGS, IDS_RS_SPEAKERTOCHANNELMAPPING, &ptr, &len );
+ if ( bResult && len == sizeof(pSpeakerToChannelMap) )
{
- memcpy(pSpeakerToChannelMap, ptr, sizeof(pSpeakerToChannelMap));
- delete [] ptr;
+ memcpy( pSpeakerToChannelMap, ptr, sizeof(pSpeakerToChannelMap) );
}
else
{
@@ -2091,6 +2098,8 @@ void CMPlayerCApp::Settings::UpdateData(bool fSave) pSpeakerToChannelMap[4][4] = 1<<3;
pSpeakerToChannelMap[4][5] = 1<<4;
}
+ if ( bResult )
+ delete [] ptr;
fAudioNormalize = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_AUDIONORMALIZE, FALSE);
fAudioNormalizeRecover = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_AUDIONORMALIZERECOVER, TRUE);
|