Archived

This forum has been archived. Please start a new discussion on GitHub.

Is this a bug?

Say hello to all ZeroC guys first:_)

I guess i found a bug of Ice::Properties.
See code below:
...
Ice::PropertiesPtr properties = Ice::createProperties();
properties->load("authconfig.txt");
try
{
int argc = 0;
communicator = Ice::initializeWithProperties(argc, 0, properties);
Ice::ObjectPrx obj = communicator->stringToProxy("bmcauth:ssl -p 10001");
//Things goes on very well now.But crashed when i swich to use code below instead
//////////////////////////////////////////////////////////////////////////
// const char* proxyProperty = "Hello.Proxy";
// string proxy = properties->getProperty(proxyProperty);
// Ice::ObjectPrx obj = communicator->stringToProxy(proxy);
//////////////////////////////////////////////////////////////////////////
// It seems that some string is deallocated on some unsuitable occasion and caused an assertion failure...
//
_proxy = BMCAuth::AuthenticationPrx::uncheckedCast(obj);
m_oproxy = _proxy->ice_twoway();
m_oproxy = m_oproxy->ice_secure(true);
m_proxy = BMCAuth::AuthenticationPrx::uncheckedCast(m_oproxy);
std::string msg;
Ice::Long res=-1;
Ice::Long closeornot = -1;
m_proxy->doPost(guid,uname,pwd,res,closeornot,msg);
}
catch(...)
{
...
}

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Could you provide a stack trace of the crash? Also, please mention which Ice version and platform you're using.

    Thanks!

    Benoit.
  • i'm using ice 2.1.0 with vc7.1 on Windows Server 2003 sp1
    here is a snapshot of the callstack(top level):
    msvcr71d.dll!operator delete(void * pUserData=0x02112810) Line 52 + 0x51 C++
    msvcp71d.dll!std::allocator<char>::deallocate(char * _Ptr=0x02112810, unsigned int __formal=32) Line 138 + 0x9 C++
    msvcp71d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy(bool _Built=true, unsigned int _Newsize=0) Line 1519 C++
    msvcp71d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() Line 458 C++
    BMCAuthen.ocx!_DllCanUnloadNow@0() + 0x1238 C++
    BMCAuthen.ocx!CAuthSDialog::OnBnClickedOk() Line 50 C++
    mfc71d.dll!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x0012c1d0, unsigned int nID=1, int nCode=0, void (void)* pfn=0x0536288d, void * pExtra=0x00000000, unsigned int nSig=53, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 89 C++
    mfc71d.dll!CCmdTarget::OnCmdMsg(unsigned int nID=1, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 396 + 0x27 C++
    mfc71d.dll!CDialog::OnCmdMsg(unsigned int nID=1, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 88 + 0x18 C++
    mfc71d.dll!CWnd::OnCommand(unsigned int wParam=1, long lParam=1185062) Line 2550 C++
    mfc71d.dll!CWnd::OnWndMsg(unsigned int message=273, unsigned int wParam=1, long lParam=1185062, long * pResult=0x0012b98c) Line 1759 + 0x1c C++
    mfc71d.dll!CWnd::WindowProc(unsigned int message=273, unsigned int wParam=1, long lParam=1185062) Line 1745 + 0x1e C++
    mfc71d.dll!AfxCallWndProc(CWnd * pWnd=0x0012c1d0, HWND__ * hWnd=0x001114ac, unsigned int nMsg=273, unsigned int wParam=1, long lParam=1185062) Line 241 + 0x1a C++
    mfc71d.dll!AfxWndProc(HWND__ * hWnd=0x001114ac, unsigned int nMsg=273, unsigned int wParam=1, long lParam=1185062) Line 389 C++
    BMCAuthen.ocx!AfxWndProcDllStatic(HWND__ * hWnd=0x001114ac, unsigned int nMsg=273, unsigned int wParam=1, long lParam=1185062) Line 53 + 0x15 C++


    Come back to the source code.

    int CAuthSDialog::DoIceJob(const std::string& guid,const std::string& uname,const std::string& pwd)
    {
    int status;
    Ice::CommunicatorPtr communicator;
    BMCAuth::AuthenticationPrx _proxy;
    Ice::PropertiesPtr properties = Ice::createProperties();
    properties->load("authconfig.txt");

    try
    {
    int argc = 0;
    communicator = Ice::initializeWithProperties(argc, 0, properties);
    std::string p = properties->getProperty("BMCAuth.Proxy");
    //Ice::ObjectPrx obj = communicator->stringToProxy("bmcauth:ssl -p 10001");
    Ice::ObjectPrx obj = communicator->stringToProxy(p);
    _proxy = BMCAuth::AuthenticationPrx::uncheckedCast(obj);
    m_oproxy = _proxy->ice_twoway();
    m_oproxy = m_oproxy->ice_secure(true);
    m_proxy = BMCAuth::AuthenticationPrx::uncheckedCast(m_oproxy);
    std::string msg;
    Ice::Long res=-1;
    Ice::Long closeornot = -1;

    m_proxy->doPost(guid,uname,pwd,res,closeornot,msg);
    //After the connection being refused by 5 times(since service is not started at all),std::string p declared above and pass as const reference had been deallocated before doPost returns.
    }
    catch(const Ice::Exception& ex)
    {
    ostringstream os;
    os<<ex;
    string exp = os.str();
    AfxMessageBox(exp.c_str(), MB_OK|MB_ICONEXCLAMATION);
    status = EXIT_FAILURE;
    }
    catch(...)
    {
    status = EXIT_FAILURE;
    }

    if(communicator)
    {
    try
    {
    communicator->destroy();
    }
    catch(const Ice::Exception& ex)
    {
    cerr << ex << endl;
    status = EXIT_FAILURE;
    }
    }
    return status;
    }
  • ok, it seems the crash has nothing to do with
    Ice::ObjectPrx obj = communicator->stringToProxy(p);
    since i use

    communicator = Ice::initializeWithProperties(argc, 0, properties);
    std::string p = properties->getProperty("BMCAuth.Proxy");
    Ice::ObjectPrx obj = communicator->stringToProxy("bmcauth:ssl -p 10001");
    //Ice::ObjectPrx obj = communicator->stringToProxy(p);
    _proxy = BMCAuth::AuthenticationPrx::uncheckedCast(obj);}


    instead but crashed as well.

    btw, i compile the code using :
    /Od /I "./" /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_USRDLL" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Zc:wchar_t /GR /YX"stdafx.h" /Fp"Debug/BMCAuthen.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Wp64 /ZI /TP
    and link it using:
    /OUT:"Debug/BMCAuthen.ocx" /INCREMENTAL /NOLOGO /DLL /DEF:".\BMCAuthen.def" /DEBUG /PDB:"Debug/BMCAuthen.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"Debug/BMCAuthen.lib" /MACHINE:X86
  • benoit
    benoit Rennes, France
    From the stack trace, it sounds like you're mixing Microsoft debug/release runtime libraries. Since you compile your program with /MDd, you should be linking with the "iced.lib" library. Can you ensure that your pogram is linked with iced.lib (and not ice.lib)?

    As an aside, I would recommend to create the communicator once and cache it somewhere instead of creating it each time a button is clicked in your GUI :). Creating the communicator is an expensive operation!

    Hope this helps!

    Benoit.
  • Thanks, benoit.
    You are right, the program is crashed because i use ice.lib instead of iced.lib.
    and thank you for the additional suggestion aswell, i'm using the code above for testing purpose only:)
    :D:D