a wierd problem about malloc action. | developer.brewmp.com a wierd problem about malloc action. | developer.brewmp.com

Developer

a wierd problem about malloc action.

Forums:

Hi all, when i malloc a buffer of 256 bytes, the content in another buffer is changed. by the way, there are some memory operation before this malloc. Has any one ever encountered this issue? Plsease give some light, thanks a lot!

dengll wrote:Hi all, when i malloc a buffer of 256 bytes, the content in another buffer is changed. by the way, there are some memory operation before this malloc. Has any one ever encountered this issue? Plsease give some light, thanks a lot!
Hi
Could you post you code snippet here so that we could actually see what's going on in your code.

dengll wrote:Hi all, when i malloc a buffer of 256 bytes, the content in another buffer is changed. by the way, there are some memory operation before this malloc. Has any one ever encountered this issue? Plsease give some light, thanks a lot!
Hi
Could you post you code snippet here so that we could actually see what's going on in your code.

1、code fragment: ( breakpoints is on "FindItem" line)
ParserXM *pXmlParser = pme->m_pXmlParser;
FindItem(pXmlParser, "page");
IntoItem(pXmlParser);
2、watch pme->m_pFile:
-pme->m_pFile 0x031fa440
- pvt 0x005f2e54
AddRef 0x00451d30
Release 0x004c5500
Readable 0x004c33d0
..............
3、After "FindItem(pXmlParser, "page");", the pme->m_pFile became:
-pme->m_pFile 0x031fa440
- pvt 0x65676170
AddRef CXX0030: Error: expression cannot be evaluated
Release CXX0030: Error: expression cannot be evaluated
Readable CXX0030: Error: expression cannot be evaluated
4、FindItem fun:
boolean FindItem(ParserXM *pXMParser, char *pName)
{
char *pszName = (char *)MALLOC(256);
if (!pXMParser || !pName || !pszName)
return FALSE;
while(pXMParser->m_pItem)
{
ZEROAT(pszName);
FindToken(pXMParser->m_pItem->Data, pszName);
if(_strcmp(pszName, pName) == 0)
{
FREEIF(pszName);
pszName = NULL;
return TRUE;
}
pXMParser->m_pItem = pXMParser->m_pItem->Next;
}
FREEIF(pszName);
pszName = NULL;
return FALSE;

1、code fragment: ( breakpoints is on "FindItem" line)
ParserXM *pXmlParser = pme->m_pXmlParser;
FindItem(pXmlParser, "page");
IntoItem(pXmlParser);
2、watch pme->m_pFile:
-pme->m_pFile 0x031fa440
- pvt 0x005f2e54
AddRef 0x00451d30
Release 0x004c5500
Readable 0x004c33d0
..............
3、After "FindItem(pXmlParser, "page");", the pme->m_pFile became:
-pme->m_pFile 0x031fa440
- pvt 0x65676170
AddRef CXX0030: Error: expression cannot be evaluated
Release CXX0030: Error: expression cannot be evaluated
Readable CXX0030: Error: expression cannot be evaluated
4、FindItem fun:
boolean FindItem(ParserXM *pXMParser, char *pName)
{
char *pszName = (char *)MALLOC(256);
if (!pXMParser || !pName || !pszName)
return FALSE;
while(pXMParser->m_pItem)
{
ZEROAT(pszName);
FindToken(pXMParser->m_pItem->Data, pszName);
if(_strcmp(pszName, pName) == 0)
{
FREEIF(pszName);
pszName = NULL;
return TRUE;
}
pXMParser->m_pItem = pXMParser->m_pItem->Next;
}
FREEIF(pszName);
pszName = NULL;
return FALSE;