Hi
I'm not sure if this a problem or just a restriction. There are heap corruption
problems with std::strings passed across the PoDoFo interface when the
following conditions are true:
- PoDoFo is compiled as a Windows DLL
- The shared C runtime DLL isn't being used for both caller and PoDoFo
(i.e. not an issue when both use the shared runtime)
Here's an example of what goes wrong:
Caller_method()
{
PoDoFo::TKeyMap& keys = token.GetDictionary().GetKeys();
for ( PoDoFo::TKeyMap::iterator it = keys.begin(); it != keys.end(); ++it )
{
PoDoFo::PdfObject* pValue = it->second;
string strValue; // no memory allocated for strValue.c_str() yet
// strValue is allocated in PoFoFo!_crtheap by ToString
// memory only allocated if strValue.size() > 16 (string::char[16]
used for short strings)
pValue->ToString( strValue );
// strValue destructor fires and tries to free strValue.c_str() from
caller!_crtheap using
// HeapFree(_crtheap, strValue.data() )
// this only works when the both caller and callee share same CRT heap (i.e.
both use shared DLL CRT)
}
}
Simple assignments suffer the same issue in Visual C++ 6.0, since std:string
shares ref counted string buffers between std::string instances (may not be
many people left using that though).
It looks like podofo_malloc and podofo_free avoid this issue for explicitly
allocated memory, but something similar would need done for std::string (a
custom STL allocator should do the trick, but that could break a lot of
existing code).
The other alternative is to require apps to use the shared CRT, but that pulls
in other dependencies (e.g. installer merge modules and the broken SxS
deployment model)
Regards
Mark
Mark Rogers - [email protected]
PowerMapper Software Ltd - http://www.powermapper.com
Quartermile 2 Edinburgh EH3 9GL Registered in Scotland No 362274
Phone +44 845 056 8475
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users