diff options
author | George Hazan <george.hazan@gmail.com> | 2012-06-24 20:29:24 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-06-24 20:29:24 +0000 |
commit | 0de67362be5fa5a1bc045701c9dc36c05c423809 (patch) | |
tree | 286b3de4550c4dc3cfd2138df983438aec4578f7 | |
parent | 61f15ba72fa1cbc4b215804b14edc70b603c9545 (diff) |
- added template mir_ptr for automatic memory deallocation using mir_free();
- mir_ptr<TCHAR> used in MSN
git-svn-id: http://svn.miranda-ng.org/main/trunk@614 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | include/m_system_cpp.h | 11 | ||||
-rw-r--r-- | protocols/MSN/msn_commands.cpp | 14 |
2 files changed, 19 insertions, 6 deletions
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index a04898e427..9d872480e9 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -38,6 +38,17 @@ extern LIST_INTERFACE li; #define HandleKeySortT -2
#define PtrKeySortT -3
+template<class T> class mir_ptr
+{
+ T* data;
+
+public:
+ __inline mir_ptr(T* _p) : data(_p) {}
+ __inline ~mir_ptr() { mir_free(data); }
+ __inline operator T*() const { return data; }
+ __inline operator INT_PTR() const { return (INT_PTR)data; }
+};
+
template<class T> struct LIST
{
typedef int (*FTSortFunc)(const T* p1, const T* p2);
diff --git a/protocols/MSN/msn_commands.cpp b/protocols/MSN/msn_commands.cpp index fbec551993..3fc028ad19 100644 --- a/protocols/MSN/msn_commands.cpp +++ b/protocols/MSN/msn_commands.cpp @@ -830,13 +830,15 @@ void CMsnProto::sttProcessStatusMessage(char* buf, unsigned len, const char* wli char* szStatMsg = ezxml_txt(ezxml_child(xmli, "PSM"));
stripBBCode(szStatMsg);
stripColorCode(szStatMsg);
- TCHAR *tszStatMsg = mir_utf8decodeT(szStatMsg);
- if (*tszStatMsg)
- DBWriteContactSettingTString(hContact, "CList", "StatusMsg", tszStatMsg);
- else
- DBDeleteContactSetting(hContact, "CList", "StatusMsg");
+ {
+ mir_ptr<TCHAR> tszStatMsg = mir_utf8decodeT(szStatMsg);
+ if (*tszStatMsg)
+ DBWriteContactSettingTString(hContact, "CList", "StatusMsg", tszStatMsg);
+ else
+ DBDeleteContactSetting(hContact, "CList", "StatusMsg");
- SendBroadcast(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, NULL, (LPARAM)tszStatMsg);
+ SendBroadcast(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, NULL, (LPARAM)tszStatMsg);
+ }
// Process current media info
const char* szCrntMda = ezxml_txt(ezxml_child(xmli, "CurrentMedia"));
|