From 991f409e2eec6c19aed25c9daffd5f7297c96811 Mon Sep 17 00:00:00 2001 From: sje Date: Tue, 5 Jun 2007 01:27:27 +0000 Subject: free copied message memory only if allocated! reorganised a little to use less dynamically allocated memory git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@198 4f64403b-2f21-0410-a795-97e2b3489a10 --- message_notify/messagenotify.cpp | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'message_notify/messagenotify.cpp') diff --git a/message_notify/messagenotify.cpp b/message_notify/messagenotify.cpp index fe37a28..1e7628a 100644 --- a/message_notify/messagenotify.cpp +++ b/message_notify/messagenotify.cpp @@ -27,7 +27,7 @@ DWORD focusTimerId = 0; PLUGININFOEX pluginInfo={ sizeof(PLUGININFOEX), "Message Notify", - PLUGIN_MAKE_VERSION(0,2,0,3), + PLUGIN_MAKE_VERSION(0,2,1,0), "Show a popup when a message is received", "Scott Ellis", "mail@scottellis.com.au", @@ -181,43 +181,35 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) { { if(IsUnicodePopupsEnabled()) { // get contact display name from clist - wchar_t *swzContactDisplayName = 0; + wchar_t swzContactDisplayName[512]; - if(unicode_system) - swzContactDisplayName = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)cd->hContact, GCDNF_UNICODE); - else { + if(unicode_system) { + wcsncpy(swzContactDisplayName, (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)cd->hContact, GCDNF_UNICODE), 512); + } else { char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)cd->hContact, 0); if(szCDN && szCDN[0]) { - int size = MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, 0, 0); - swzContactDisplayName = (wchar_t *) malloc(sizeof(wchar_t) * size); - MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, swzContactDisplayName, size); + MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, swzContactDisplayName, 512); } else { - swzContactDisplayName = (wchar_t *) malloc(sizeof(wchar_t) * (wcslen(TranslateT("(Unknown)") + 1))); - wcscpy(swzContactDisplayName, TranslateT("(Unknown)")); + wcsncpy(swzContactDisplayName, TranslateT("(Unknown)"), 512); } } - wchar_t *msg = 0; - - // does blob contain unicode message? if(cd->blobsize) { + // does blob contain unicode message? int msglen = strlen((char *)cd->blob) + 1; if(msglen != cd->blobsize && wcslen((wchar_t *)(&cd->blob[msglen]))) { // yes - msg = (wchar_t *)(&cd->blob[msglen]); - ShowPopupW(cd->hContact, swzContactDisplayName, msg); + ShowPopupW(cd->hContact, swzContactDisplayName, (wchar_t *)(&cd->blob[msglen])); } else { // no, convert to unciode - int size = MultiByteToWideChar(code_page, 0, (char *) cd->blob, -1, 0, 0); - msg = (wchar_t *) malloc(sizeof(wchar_t) * size); - MultiByteToWideChar(code_page, 0, (char *) cd->blob, -1, msg, size); + wchar_t msg[MAX_SECONDLINE]; + MultiByteToWideChar(code_page, 0, (char *) cd->blob, -1, msg, MAX_SECONDLINE); ShowPopupW(cd->hContact, swzContactDisplayName, msg); - free(msg); } - } else { // no message + } else { + // no message ShowPopupW(cd->hContact, swzContactDisplayName, 0); } - if(!unicode_system) free(swzContactDisplayName); } else { char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)cd->hContact, 0); if(szCDN && szCDN[0]) { @@ -232,7 +224,8 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) { } } - delete[] cd->blob; + if(cd->blobsize) + delete[] cd->blob; delete cd; return 0; -- cgit v1.2.3