+ simplify fix to avoid memory leaks in keySequenceToAccel
This commit is contained in:
parent
7ee6214415
commit
d8430f191f
|
@ -621,29 +621,19 @@ void Command::applyCommandData(const char* context, Action* action)
|
|||
const char* Command::keySequenceToAccel(int sk) const
|
||||
{
|
||||
/* Local class to ensure free()'ing the strings allocated below */
|
||||
class StringMap : public std::map<int, char *> {
|
||||
public:
|
||||
|
||||
~StringMap() {
|
||||
for (iterator i = begin(); i != end(); ++i)
|
||||
free(i->second);
|
||||
}
|
||||
};
|
||||
typedef std::map<int, std::string> StringMap;
|
||||
static StringMap strings;
|
||||
StringMap::iterator i = strings.find(sk);
|
||||
|
||||
if (i != strings.end())
|
||||
return i->second;
|
||||
return i->second.c_str();
|
||||
|
||||
QKeySequence::StandardKey type = (QKeySequence::StandardKey)sk;
|
||||
QKeySequence ks(type);
|
||||
QString qs = ks.toString();
|
||||
QByteArray data = qs.toLatin1();
|
||||
#if defined (_MSC_VER)
|
||||
return strings[sk] = _strdup((const char*)data);
|
||||
#else
|
||||
return strings[sk] = strdup((const char*)data);
|
||||
#endif
|
||||
|
||||
return (strings[sk] = static_cast<const char*>(data)).c_str();
|
||||
}
|
||||
|
||||
void Command::adjustCameraPosition()
|
||||
|
|
Loading…
Reference in New Issue
Block a user