CyGetDeviceInfoVidPid and CyGetDeviceInfo handle leak

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
yosuke
Level 1
Level 1
5 sign-ins First reply posted First question asked
Hello I am using USBserialSDK(x64,windows) to control CY7C65211. But when CyGetDeviceInfoVidPid or CyGetDeviceInfo is called, this seem to have a handle leak. I use these function to poll the device is connected or not. cyusbserial.dll version is 1.0.3.81 . Regards Yosuke.
0 Likes
1 Solution
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi Yosuke,

The API to close a device handle is CyClose (CY_HANDLE) as mentioned in section 4.7 in the USB Serial API Guide: https://www.cypress.com/file/123321/download 

The reason for not closing the handle is whenever you call CyGetDeviceInfo API, a linked list is created which stores the device handle information for all the devices connected. Since we are not closing the handle, CyOpen() can use the same information and hence eliminates the need to re-create the linked list. 

You can close the handle if needed. The information regarding other devices will be deleted at the time of application closure.

Regards,

Mallika

View solution in original post

0 Likes
6 Replies
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi Yosuke,

The API to close a device handle is CyClose (CY_HANDLE) as mentioned in section 4.7 in the USB Serial API Guide: https://www.cypress.com/file/123321/download 

The reason for not closing the handle is whenever you call CyGetDeviceInfo API, a linked list is created which stores the device handle information for all the devices connected. Since we are not closing the handle, CyOpen() can use the same information and hence eliminates the need to re-create the linked list. 

You can close the handle if needed. The information regarding other devices will be deleted at the time of application closure.

Regards,

Mallika

0 Likes
yosuke
Level 1
Level 1
5 sign-ins First reply posted First question asked

Thank you for your quick reply.

Let me check my understanding is correct.

The handles are  retrieved internally when cyGetDeviceInfoVidPid is called.

So ,to prevent a handle leak,cyOpen and cyClose are should be called after cyGetDeviceInfoVidPid.

Is correct?

Below is current pseudo code.

    while (1) {
        //Array size of cyDeviceInfoList is 16 
        cyReturnStatus = CyGetDeviceInfoVidPid(cyVidPid, deviceID, (PCY_DEVICE_INFO)&cyDeviceInfoList, &cyNumDevices, 16);
    }
 
Should I modify it as follows to fix the issue?
 
    while (1) {
        //Array size of cyDeviceInfoList is 16 
        cyReturnStatus = CyGetDeviceInfoVidPid(cyVidPid, deviceID, (PCY_DEVICE_INFO)&cyDeviceInfoList, &cyNumDevices, 16);
        for (int i=0;i<cyNumDevices;,i++){
           CY_HANDLE handle;
           CyOpen(i, 0, &handle);
           CyClose(handle); 
         }

    }
 
Regards.
0 Likes
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

Yes it seems correct. Using CyClose () shouldn't cause any issues.

Regards,

Mallika

0 Likes

I tried the modified code, but the number of handles still increases with each CyGetDeviceInfoVidPid function call.

Could you please investigate if there is a problem with the CyGetDeviceInfoVidPid function?

Regards.

Yosuke

yosuke_0-1627522453369.png

 

0 Likes
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

Apologies for the delay in response. Did you use Cy_Close()?

0 Likes

Hi,

Yes, I used CyGetDeviceInfoVidPid() with CYOPEN() and CYCLOSE(),but still get a handle leak.

The handle I mean here is not the CY_HANDLE, but the handle displayed in the Task Manager.(see below  https://mywindowshub.com/how-to-check-task-manager-handles-for-solving-port-exhaustion-issues-on-win... )

With each call to CyGetDeviceInfoVidPid or CyGetDeviceInfo, the number of handles increases. This means that a handle leak is occurring.

Regards.

Yosuke

0 Likes