Update of /cvsroot/pywin32/pywin32/Pythonwin
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20504/Pythonwin
Modified Files:
ddeconv.cpp ddemodule.h stddde.cpp
Log Message:
Fix broken memory allocation in DDE module and support for unicode builds
without leaking mem
Index: ddemodule.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/ddemodule.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ddemodule.h 13 Nov 2008 04:04:50 -0000 1.2
--- ddemodule.h 6 Dec 2008 00:34:06 -0000 1.3
***************
*** 24,28 ****
};
-
template <class T>
class PythonDDETopicFramework : public T
--- 24,27 ----
***************
*** 39,43 ****
return !rc;
}
! virtual BOOL NSRequest(const TCHAR * szItem, void** ppData, DWORD* dwSize)
{
PyObject *args = Py_BuildValue("(N)", PyWinObject_FromTCHAR(szItem));
--- 38,42 ----
return !rc;
}
! virtual BOOL NSRequest(const TCHAR *szItem, CDDEAllocator &allocr)
{
PyObject *args = Py_BuildValue("(N)", PyWinObject_FromTCHAR(szItem));
***************
*** 45,55 ****
CVirtualHelper helper("Request", this);
if (helper.call_args(args) ) {
! TCHAR * strret ;
if (helper.retval(strret)) {
! PyObject * look ;
! helper.retval(look) ;
! *dwSize = PyObject_Length(look)+1 ;
! *ppData = (void*)strret ;
! return TRUE ;
}
}
--- 44,52 ----
CVirtualHelper helper("Request", this);
if (helper.call_args(args) ) {
! CString strret;
if (helper.retval(strret)) {
! // seems strange we can't use DdeCreateStringHandle, but that is
! // a different handle type
! return allocr.Alloc(strret);
}
}
Index: ddeconv.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/ddeconv.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ddeconv.cpp 13 Nov 2008 04:04:50 -0000 1.2
--- ddeconv.cpp 6 Dec 2008 00:34:06 -0000 1.3
***************
*** 82,95 ****
if (!PyWinObject_AsTCHAR(obCmd, &szCmd, FALSE))
return NULL;
GUI_BGN_SAVE;
! void *ppData ;
! DWORD pdwSize ;
! BOOL ok = pConv->Request(szCmd, &ppData, &pdwSize);
GUI_END_SAVE;
PyWinObject_FreeTCHAR(szCmd);
if (!ok)
RETURN_DDE_ERR("Request failed");
! PyObject * result = PyWinObject_FromTCHAR((TCHAR *)ppData);
! free(ppData) ;
return result ;
}
--- 82,93 ----
if (!PyWinObject_AsTCHAR(obCmd, &szCmd, FALSE))
return NULL;
+ CString ret;
GUI_BGN_SAVE;
! BOOL ok = pConv->Request(szCmd, ret);
GUI_END_SAVE;
PyWinObject_FreeTCHAR(szCmd);
if (!ok)
RETURN_DDE_ERR("Request failed");
! PyObject * result = PyWinObject_FromTCHAR((const TCHAR *)ret);
return result ;
}
Index: stddde.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/stddde.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** stddde.cpp 13 Nov 2008 09:48:01 -0000 1.7
--- stddde.cpp 6 Dec 2008 00:34:06 -0000 1.8
***************
*** 178,182 ****
}
! BOOL CDDEItem::Request(UINT wFmt, void** ppData, DWORD* pdwSize)
{
return FALSE;
--- 178,182 ----
}
! BOOL CDDEItem::Request(UINT wFmt, CDDEAllocator &allocr)
{
return FALSE;
***************
*** 184,188 ****
//CT BEGIN
! BOOL CDDEItem::NSRequest(const TCHAR* szItem, void** ppData, DWORD* pdwSize)
{
return FALSE;
--- 184,188 ----
//CT BEGIN
! BOOL CDDEItem::NSRequest(const TCHAR* szItem, CDDEAllocator &allocr)
{
return FALSE;
***************
*** 240,250 ****
}
! BOOL CDDEStringItem::Request(UINT wFmt, void** ppData, DWORD* pdwSize)
{
ASSERT(wFmt == CF_TEXT);
! ASSERT(ppData);
! *ppData = (void*)(const TCHAR*)m_strData;
! *pdwSize = m_strData.GetLength() + 1; // allow for the null
! return TRUE;
}
--- 240,247 ----
}
! BOOL CDDEStringItem::Request(UINT wFmt, CDDEAllocator &allocr)
{
ASSERT(wFmt == CF_TEXT);
! return allocr.Alloc(m_strData);
}
***************
*** 320,324 ****
BOOL CDDETopic::Request(UINT wFmt, const TCHAR* pszItem,
! void** ppData, DWORD* pdwSize)
{
//
--- 317,321 ----
BOOL CDDETopic::Request(UINT wFmt, const TCHAR* pszItem,
! CDDEAllocator &allocr)
{
//
***************
*** 331,343 ****
//CT BEGIN
if (pItem->m_strName == "") {
! BOOL ret = NSRequest(pszItem, ppData, pdwSize);
return ret ;
}
//CT END
! return pItem->Request(wFmt, ppData, pdwSize);
}
//CT BEGIN
! BOOL CDDETopic::NSRequest(const TCHAR * szItem, void** ppData, DWORD* dwsize)
{
return FALSE ;
--- 328,340 ----
//CT BEGIN
if (pItem->m_strName == "") {
! BOOL ret = NSRequest(pszItem, allocr);
return ret ;
}
//CT END
! return pItem->Request(wFmt, allocr);
}
//CT BEGIN
! BOOL CDDETopic::NSRequest(const TCHAR *szItem, CDDEAllocator &allocr)
{
return FALSE ;
***************
*** 542,551 ****
}
! BOOL CDDEConv::Request(const TCHAR* pszItem, void** ppData, DWORD* pdwSize)
{
ASSERT(m_pServer);
ASSERT(pszItem);
- ASSERT(ppData);
- ASSERT(pdwSize);
CHSZ hszItem (m_pServer, pszItem);
--- 539,546 ----
}
! BOOL CDDEConv::Request(const TCHAR* pszItem, CString &ret)
{
ASSERT(m_pServer);
ASSERT(pszItem);
CHSZ hszItem (m_pServer, pszItem);
***************
*** 554,558 ****
--- 549,557 ----
m_hConv,
hszItem,
+ #if defined(UNICODE)
+ CF_UNICODETEXT,
+ #else
CF_TEXT,
+ #endif
XTYP_REQUEST,
DDE_TIMEOUT,
***************
*** 560,567 ****
if (!hData) {
-
- // Failed
- *pdwSize = 0;
- *ppData = NULL;
return FALSE;
}
--- 559,562 ----
***************
*** 570,581 ****
// Copy the result data
//
!
! BYTE* pData = ::DdeAccessData(hData, pdwSize);
! ASSERT(*pdwSize);
! *ppData = new char[*pdwSize];
! ASSERT(*ppData);
! memcpy(*ppData, pData, *pdwSize);
::DdeUnaccessData(hData);
!
return TRUE;
}
--- 565,578 ----
// Copy the result data
//
! DWORD dwSize;
! BYTE* pData = ::DdeAccessData(hData, &dwSize);
! DWORD nChars = (dwSize / sizeof(TCHAR))-1;
! ret = CString((TCHAR *)pData, nChars);
::DdeUnaccessData(hData);
! // MSDN sez 'When an application has finished using the data handle
! // returned by DdeClientTransaction, the application should free the
! // handle by calling the DdeFreeDataHandle function.' - which would
! // be about now!
! ::DdeFreeDataHandle(hData);
return TRUE;
}
***************
*** 693,697 ****
IMPLEMENT_DYNCREATE(CDDESystemItem_TopicList, CDDESystemItem);
! BOOL CDDESystemItem_TopicList::Request(UINT wFmt, void** ppData, DWORD* pdwSize)
{
//
--- 690,694 ----
IMPLEMENT_DYNCREATE(CDDESystemItem_TopicList, CDDESystemItem);
! BOOL CDDESystemItem_TopicList::Request(UINT wFmt, CDDEAllocator &allocr)
{
//
***************
*** 728,740 ****
// Set up the return info
//
!
! *ppData = (void*)(const TCHAR*)strTopics;
! *pdwSize = strTopics.GetLength() + 1; // include room for the NULL
! return TRUE;
}
IMPLEMENT_DYNCREATE(CDDESystemItem_ItemList, CDDESystemItem);
! BOOL CDDESystemItem_ItemList::Request(UINT wFmt, void** ppData, DWORD* pdwSize)
{
//
--- 725,734 ----
// Set up the return info
//
! return allocr.Alloc(strTopics);
}
IMPLEMENT_DYNCREATE(CDDESystemItem_ItemList, CDDESystemItem);
! BOOL CDDESystemItem_ItemList::Request(UINT wFmt, CDDEAllocator &allocr)
{
//
***************
*** 769,781 ****
// Set up the return info
//
!
! *ppData = (void*)(const TCHAR*)strItems;
! *pdwSize = strItems.GetLength() + 1; // include room for the NULL
! return TRUE;
}
IMPLEMENT_DYNCREATE(CDDESystemItem_FormatList, CDDESystemItem);
! BOOL CDDESystemItem_FormatList::Request(UINT wFmt, void** ppData, DWORD* pdwSize)
{
//
--- 763,772 ----
// Set up the return info
//
! return allocr.Alloc(strItems);
}
IMPLEMENT_DYNCREATE(CDDESystemItem_FormatList, CDDESystemItem);
! BOOL CDDESystemItem_FormatList::Request(UINT wFmt, CDDEAllocator &allocr)
{
//
***************
*** 850,857 ****
// Set up the return info
//
!
! *ppData = (void*)(const TCHAR*)strFormats;
! *pdwSize = strFormats.GetLength() + 1; // include romm for the NULL
! return TRUE;
}
--- 841,845 ----
// Set up the return info
//
! return allocr.Alloc(strFormats);
}
***************
*** 859,866 ****
BOOL CDDEServerSystemTopic::Request(UINT wFmt, const TCHAR* pszItem,
! void** ppData, DWORD* pdwSize)
{
m_pServer->Status(_T("System topic request: %s"), pszItem);
! return CDDETopic::Request(wFmt, pszItem, ppData, pdwSize);
}
--- 847,854 ----
BOOL CDDEServerSystemTopic::Request(UINT wFmt, const TCHAR* pszItem,
! CDDEAllocator &allocr)
{
m_pServer->Status(_T("System topic request: %s"), pszItem);
! return CDDETopic::Request(wFmt, pszItem, allocr);
}
***************
*** 1694,1702 ****
// a generic one for the topic
//
Status(_T("Request %s|%s"), (const TCHAR*)strTopic, (const TCHAR*)strItem);
dwLength = 0;
! if (!Request(wFmt, strTopic, strItem, &pData, &dwLength)) {
!
//
// Nobody accepted the request
--- 1682,1691 ----
// a generic one for the topic
//
+ { // scope for locals.
+ CDDEAllocator allocr(m_dwDDEInstance, hszItem, wFmt, phReturnData);
Status(_T("Request %s|%s"), (const TCHAR*)strTopic, (const TCHAR*)strItem);
dwLength = 0;
! if (!Request(wFmt, strTopic, strItem, allocr)) {
//
// Nobody accepted the request
***************
*** 1710,1725 ****
}
! //
! // There is some data so build a DDE data object to return
! //
!
! *phReturnData = ::DdeCreateDataHandle(m_dwDDEInstance,
! (unsigned char*)pData,
! dwLength,
! 0,
! hszItem,
! wFmt,
! 0);
!
break;
--- 1699,1704 ----
}
! } // end locals scope
! // Data already setup via 'allocr' param, so we are done.
break;
***************
*** 1805,1809 ****
BOOL CDDEServer::Request(UINT wFmt, const TCHAR* pszTopic, const TCHAR* pszItem,
! void** ppData, DWORD* pdwSize)
{
//
--- 1784,1788 ----
BOOL CDDEServer::Request(UINT wFmt, const TCHAR* pszTopic, const TCHAR* pszItem,
! CDDEAllocator &allocr)
{
//
***************
*** 1814,1818 ****
if (!pTopic) return FALSE;
! return pTopic->Request(wFmt, pszItem, ppData, pdwSize);
}
--- 1793,1797 ----
if (!pTopic) return FALSE;
! return pTopic->Request(wFmt, pszItem, allocr);
}
|