• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

TnrUSBDevice is only created, never destroyed

Started by J.Beck, September 21, 2011, 12:18:05 pm

Previous topic - Next topic

J.Beck

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

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

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

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

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

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.