Click here to Skip to main content
15,905,914 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: header file Pin
Christian Graus4-Apr-05 14:22
protectorChristian Graus4-Apr-05 14:22 
GeneralRe: header file Pin
NewbieStats4-Apr-05 15:06
NewbieStats4-Apr-05 15:06 
GeneralRe: header file Pin
ThatsAlok4-Apr-05 18:33
ThatsAlok4-Apr-05 18:33 
GeneralRe: header file Pin
mpapeo4-Apr-05 21:47
mpapeo4-Apr-05 21:47 
GeneralRe: header file Pin
David Crow4-Apr-05 17:11
David Crow4-Apr-05 17:11 
GeneralRe: header file Pin
Christian Graus4-Apr-05 17:16
protectorChristian Graus4-Apr-05 17:16 
GeneralRe: header file Pin
Ryan Binns4-Apr-05 18:37
Ryan Binns4-Apr-05 18:37 
GeneralMSXML Memory Leak Pin
Demián Gutierrez4-Apr-05 11:44
Demián Gutierrez4-Apr-05 11:44 
Hello, I'm parsing an XML on a deskband client using SAX: Here is the code:

<br />
// Parse response<br />
CoInitialize(NULL); <br />
ISAXXMLReader* pRdr = NULL;<br />
<br />
HRESULT hr = CoCreateInstance(__uuidof(SAXXMLReader), NULL, CLSCTX_ALL,<br />
                           __uuidof(ISAXXMLReader), (void **)&pRdr);<br />
<br />
if(!FAILED(hr)) <br />
{<br />
  hr = pRdr->putContentHandler(&m_whizzWnd->m_whizzHandler);<br />
<br />
  VARIANT var;<br />
  VariantInit(&var);<br />
  V_BSTR(&var) = SysAllocString(wresp.c_str());<br />
  V_VT(&var) = VT_BSTR;<br />
<br />
  hr = pRdr->parse(var);<br />
<br />
  VariantClear(&var);<br />
  //SysFreeString(V_BSTR(&var));<br />
<br />
  pRdr->Release();<br />
} else {<br />
  MessageBox(NULL, TEXT("Error"), NULL, MB_ICONASTERISK);<br />
}<br />
<br />
CoUninitialize();<br />
//CoFreeUnusedLibraries();<br />


The problem is that I have reports of memory leaks generated by that code. I'm detecting the memory leaks with the following code after the last include in all my cpp files:

<br />
#include <crtdbg.h><br />
<br />
#ifdef _DEBUG<br />
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />


And with the following class (I create an instance to begin test and get a memory leak report when the instance is deleted).

<br />
class FindMemoryLeaks<br />
{<br />
	_CrtMemState m_checkpoint;<br />
public:<br />
<br />
	FindMemoryLeaks()<br />
	{<br />
		_CrtMemCheckpoint(&m_checkpoint);<br />
	};<br />
<br />
	~FindMemoryLeaks()<br />
	{<br />
		_CrtMemState checkpoint;<br />
		_CrtMemCheckpoint(&checkpoint);<br />
		_CrtMemState diff;<br />
		_CrtMemDifference(&diff, &m_checkpoint, &checkpoint);<br />
		_CrtMemDumpStatistics(&diff);<br />
		_CrtMemDumpAllObjectsSince(&diff);<br />
	};<br />
};<br />


Any way, I have two kinds of memory leaks reports, the nice ones (no problem because I have file/line number)

<br />
Data: << r e s p o n s > 3C 00 72 00 65 00 73 00 70 00 6F 00 6E 00 73 00 <br />
c:\eclipse\workspace\gxclientcpp\gxclientcpp\gxclient\deskband\cwhizzmanager.cpp(348) : {267} normal block at 0x00D97FE0, 4 bytes long.<br />


And the ugly ones, because they DON'T report file/line number Cry | :(( :

<br />
 Data: <A 5 0 0 p l u s > 41 00 35 00 30 00 30 00 70 00 6C 00 75 00 73 00 <br />
{460} normal block at 0x00D9F5F8, 32 bytes long.<br />


The funny thing is that the A500plus comes in a character and in an attribute of an XML tagConfused | :confused:

The Content handler seems to be ok:

<br />
void MyContent::GetSafeValue(wstring &target, ISAXAttributes *attrs, LPTSTR name) {<br />
	size_t len1;<br />
	int len2;<br />
	StringCchLength(name, STRSAFE_MAX_CCH, &len1);<br />
	LPTSTR value;<br />
<br />
	if (attrs->getValueFromQName(name, len1, &value, &len2) == E_INVALIDARG) {<br />
		target = TEXT("");<br />
	} else {<br />
		target = value;<br />
		SysFreeString(value);<br />
	}<br />
}<br />
<br />
HRESULT STDMETHODCALLTYPE MyContent::startElement(wchar_t __RPC_FAR *pwchNamespaceUri,<br />
	int cchNamespaceUri, wchar_t __RPC_FAR *pwchLocalName,<br />
	int cchLocalName, wchar_t __RPC_FAR *pwchRawName,<br />
	int cchRawName, ISAXAttributes __RPC_FAR *pAttributes)<br />
{<br />
	m_characters.clear(); // This is a wstring used to get the text of a tag<br />
<br />
	if (!wcscmp(pwchRawName, TEXT("response"))) {<br />
		wstring boolStr;<br />
<br />
		GetSafeValue(boolStr, pAttributes, TEXT("hasPrev"));<br />
<br />
		if (!wcscmp(boolStr.c_str(), TEXT("true"))) {<br />
			m_hasPrev = TRUE;<br />
		} else {<br />
			m_hasPrev = FALSE;<br />
		}<br />
<br />
		GetSafeValue(boolStr, pAttributes, TEXT("hasNext"));<br />
<br />
		if (!wcscmp(boolStr.c_str(), TEXT("true"))) {<br />
			m_hasNext = TRUE;<br />
		} else {<br />
			m_hasNext = FALSE;<br />
		}<br />
	}<br />
        // And more...<br />
	return S_OK;<br />
}<br />
<br />
HRESULT STDMETHODCALLTYPE MyContent::characters(wchar_t __RPC_FAR *pwchChars, int cchChars)<br />
{<br />
	wstring aux(pwchChars);<br />
	m_characters.append(aux.substr(0, cchChars));<br />
	return S_OK;<br />
}<br />


Believe me, there seems to be nothing extrange there (no more than the GetSafeValue), and there are no obvious memory leaks (And the file is a little big to post it here)

If any one sees the mistake I would be grateful for everBig Grin | :-D

Regards, Demián
GeneralShowHTMLDialog working with XP not Win98 Pin
georgiek504-Apr-05 9:37
georgiek504-Apr-05 9:37 
GeneralRe: ShowHTMLDialog working with XP not Win98 Pin
Neville Franks4-Apr-05 11:07
Neville Franks4-Apr-05 11:07 
GeneralRe: ShowHTMLDialog working with XP not Win98 Pin
georgiek504-Apr-05 11:48
georgiek504-Apr-05 11:48 
GeneralRe: ShowHTMLDialog working with XP not Win98 Pin
Neville Franks4-Apr-05 11:56
Neville Franks4-Apr-05 11:56 
GeneralRe: ShowHTMLDialog working with XP not Win98 Pin
Michael Dunn4-Apr-05 12:47
sitebuilderMichael Dunn4-Apr-05 12:47 
GeneralRe: ShowHTMLDialog working with XP not Win98 Pin
georgiek505-Apr-05 5:46
georgiek505-Apr-05 5:46 
GeneralCTreeCtrl items highlight Pin
Maximilien4-Apr-05 8:10
Maximilien4-Apr-05 8:10 
GeneralRe: CTreeCtrl items highlight Pin
Neville Franks4-Apr-05 11:16
Neville Franks4-Apr-05 11:16 
GeneralRe: CTreeCtrl items highlight Pin
Maximilien4-Apr-05 12:47
Maximilien4-Apr-05 12:47 
GeneralResources not included Pin
dabs4-Apr-05 8:10
dabs4-Apr-05 8:10 
Questionhow to write in text file Pin
smarty124-Apr-05 7:55
smarty124-Apr-05 7:55 
AnswerRe: how to write in text file Pin
NewbieStats4-Apr-05 9:24
NewbieStats4-Apr-05 9:24 
GeneralSecure FTP Pin
Member 18509854-Apr-05 6:39
Member 18509854-Apr-05 6:39 
GeneralRe: Secure FTP Pin
RobJones4-Apr-05 7:27
RobJones4-Apr-05 7:27 
GeneralScrollBar Message Handling Pin
blinkered4-Apr-05 6:28
blinkered4-Apr-05 6:28 
GeneralRe: ScrollBar Message Handling Pin
PJ Arends4-Apr-05 8:26
professionalPJ Arends4-Apr-05 8:26 
GeneralHelp Urgent, Windows folder size without file searching Pin
inbakumar.G4-Apr-05 5:57
inbakumar.G4-Apr-05 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.