Fix memory leak on error return from wxMsgCatalogFile::FillHash().
Use wxScopedPtr to make memory management simpler and to ensure that all pointers allocated in this function are deleted: this wasn't the case when we returned false earlier due to the MO file being invalid. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75954 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f5033eec65
commit
a4cc201e76
@ -46,6 +46,7 @@
|
||||
#include "wx/filename.h"
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/fontmap.h"
|
||||
#include "wx/scopedptr.h"
|
||||
#include "wx/stdpaths.h"
|
||||
#include "wx/private/threadinfo.h"
|
||||
|
||||
@ -1188,7 +1189,8 @@ bool wxMsgCatalogFile::FillHash(wxStringToStringHashMap& hash,
|
||||
|
||||
// conversion to use to convert catalog strings to the GUI encoding
|
||||
wxMBConv *inputConv = NULL;
|
||||
wxMBConv *inputConvPtr = NULL; // same as inputConv but safely deleteable
|
||||
|
||||
wxScopedPtr<wxMBConv> inputConvPtr; // just to delete inputConv if needed
|
||||
|
||||
if ( !m_charset.empty() )
|
||||
{
|
||||
@ -1198,8 +1200,11 @@ bool wxMsgCatalogFile::FillHash(wxStringToStringHashMap& hash,
|
||||
if ( encCat != wxLocale::GetSystemEncoding() )
|
||||
#endif
|
||||
{
|
||||
inputConvPtr =
|
||||
inputConv = new wxCSConv(m_charset);
|
||||
|
||||
// As we allocated it ourselves, we need to delete it, so ensure
|
||||
// this happens.
|
||||
inputConvPtr.reset(inputConv);
|
||||
}
|
||||
}
|
||||
else // no need or not possible to convert the encoding
|
||||
@ -1217,9 +1222,9 @@ bool wxMsgCatalogFile::FillHash(wxStringToStringHashMap& hash,
|
||||
// conversion to apply to msgid strings before looking them up: we only
|
||||
// need it if the msgids are neither in 7 bit ASCII nor in the same
|
||||
// encoding as the catalog
|
||||
wxCSConv *sourceConv = msgIdCharset.empty() || (msgIdCharset == m_charset)
|
||||
? NULL
|
||||
: new wxCSConv(msgIdCharset);
|
||||
wxScopedPtr<wxCSConv> sourceConv;
|
||||
if ( !msgIdCharset.empty() && (msgIdCharset != m_charset) )
|
||||
sourceConv.reset(new wxCSConv(msgIdCharset));
|
||||
#endif // !wxUSE_UNICODE
|
||||
|
||||
for (size_t32 i = 0; i < m_numStrings; i++)
|
||||
@ -1275,11 +1280,6 @@ bool wxMsgCatalogFile::FillHash(wxStringToStringHashMap& hash,
|
||||
}
|
||||
}
|
||||
|
||||
#if !wxUSE_UNICODE
|
||||
delete sourceConv;
|
||||
#endif
|
||||
delete inputConvPtr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user