Author Topic: TnrUSBDevice is only created, never destroyed  (Read 953 times)

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
TnrUSBDevice is only created, never destroyed
« on: September 21, 2011, 03:18:05 pm »
Hello,

I placed some logging on the routines TnrUsbDevice.Create and TnrUsbDevice.Destroy and noticed that everytime a WM_DeviceChnage message appears, a bunch of TnrUsbDevice objects are created, but there is never a call to the Destroy methode. I don't beleave that this can be correct, this should lead to a memory leak.
Maybe I'm completly wrong...

Thanks a lot for your help!





Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: TnrUSBDevice is only created, never destroyed
« Reply #1 on: September 21, 2011, 06:20:08 pm »
Hello

Thank you for your information.

We have fixed several resource leaks in USB implementation today.
Now version 9.23 is uploading to servers and will be available in the next two hours.
Please download and try.

Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: TnrUSBDevice is only created, never destroyed
« Reply #2 on: September 22, 2011, 01:02:02 pm »
Hello Mr. Novgorodov,

thanks for the new version 9.23, which now calls the destructor, if a device disappears.

Now I have a new effect, it can be demonstrated with USBPipeDemo. If i play arround with plugging and unplugging usb devices and hubs, sometimes an exception (Integer overflow) appears in the procedure TnrUsbDevice.Update in the line:
 
  for i := 0 to fPort.ConnectInfo^.NumberOfOpenPipes - 1 do begin

I can reproduce this effect in 9 of 10 tries with the following sequence:

- start USBPipeDemo
- connect an USB hub to the system
- connect a USB device to the hub
- unplug hub
- connect hub again to the system
-> exception

Annother question regarding 9.23:

During a call to TnrUSB.Update all TnrUSBDevices are destroyed and recreated. What happens with a Thread in TUSBPipePair which is just using the device being destroyed?

Best regards
Joachim

Thanks for your help,

Best regards

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: TnrUSBDevice is only created, never destroyed
« Reply #3 on: September 22, 2011, 05:14:07 pm »
Hello

Thank you for your information.

We will try to check situation with plug-in exception over usb hub.
While you can try wrap WM_DEVICECHANGE handler in try .. except construction.

TnrUsbPipePair does not related with UsbDevice object after activation. It monitors incoming data until you will close it or physical usb device will be removed. You can try to test.

Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

J.Beck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: TnrUSBDevice is only created, never destroyed
« Reply #4 on: September 26, 2011, 07:52:34 am »
Hello,

I think I found the reason for the exception. It seems to happen that Devices appear, where the number of Pipes is 0. Then we get an exception because NumberOfOpenPipes is a cardinal, where you cannot subtract 1, if it is 0.

I changed the code in nrUsbMan.Pas as follows:

->>>  if fPort.ConnectInfo^.NumberOfOpenPipes > 0 then
  for i := 0 to fPort.ConnectInfo^.NumberOfOpenPipes - 1 do begin
    j := Add;
.....

Now it seems to work.

Best regards
J.Beck

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: TnrUSBDevice is only created, never destroyed
« Reply #5 on: September 26, 2011, 08:47:17 am »
Hello

Thank you very much for your information.
We will check on our side and will include this modification in the next release.


Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.