Author Topic: Toshiba stack crash on Close()  (Read 2061 times)

Offline david_dcl

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Toshiba stack crash on Close()
« on: June 10, 2014, 06:52:23 AM »
Hi,

Recently I added a call to CwclServer::Close() in the function that is hooked to the event CwclServer::OnDisconnected. This worked as expected on the Microsoft stacks, however on the Toshiba stack it causes a crash. I require this as I do not want to listen for inbound connections after the the remote side has disconnected.

This crash happens because CloseToshiba() gets called twice, and the second time it deletes the now NULL m_pSerialClient (which got deleted on the first call).

in the CwclCustomServerConnection::Close(), the third line "Disconnect()" triggers the callback, which in turn calls Close(), after which Close() continues and calls CloseTosiba() on an already closed stack.

adding

if (m_ToshibaState == tssClosed)
      return;

to the top of CloseToshiba() fixed the problem.

Is calling Close() inside the disconnect event handler OK? and if not is there a another way to close (stop the server listening) when the client disconnects.

Please note that I will be away for the next few days, so may be slow to reply if you need more information about this issue

Regards
David

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Toshiba stack crash on Close()
« Reply #1 on: June 10, 2014, 08:10:22 AM »
Hi,

Thnak you for your very detailed report about this issue. I have to check that out and fix it. Calling Close inside OnDisconnect should be possible so this is the bug which I must fix. Your solution (adding
if (m_ToshibaState == tssClosed)
      return;
)

looks good as temporary solution.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Toshiba stack crash on Close()
« Reply #2 on: June 10, 2014, 10:53:06 AM »
Hi,

I did lot of tests with different devices (including simple CwclClient->CwclServer connection and cell phone->CwclOPPServer) and could not reproduce the issue. Can you send me any code snippet/test project which reproduces the issue?

Offline david_dcl

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Toshiba stack crash on Close()
« Reply #3 on: June 15, 2014, 11:50:22 PM »
Have emailed you some code,

Cheers
David

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Toshiba stack crash on Close()
« Reply #4 on: June 16, 2014, 12:05:20 AM »
OK got it.
« Last Edit: June 16, 2014, 06:08:08 AM by Mike Petrichenko »

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Toshiba stack crash on Close()
« Reply #5 on: June 16, 2014, 06:11:01 AM »
Just took a look on your code. Actualy it's a mistake in your code (not sure it can be called bug). You cann Server->Close inside OnConnect and OnDisconnect. When device connects to your server OnConnect fires. You call Close. OnDisconnect fires and you call Close once again.

 

Sitemap 1 2 3 4 5 6 7 8 9