none
DhcpEnumSubnets RRS feed

  • Question

  • Using: Visual C++ 2005

    CLI Interop (Dll for consumption by C# clients).

    Windows api: dhcpsapi.h

    When calling DhcpEnumSubnetClients, the online documentation does not state anything freeing Un-Managed memory:
    DhcpEnumSubnetClients(pwszServerIpAddress, dwSubnetAddress, &resumeHandle, dwPreferredMaximumBytes, &pClientInfo, &dwClientsRead, &dwClientsTotal );

    Previous call, gets you a pointer to: LPDHCP_CLIENT_INFO_ARRAY.

    Do I need to free each individual element  in [LPDHCP_CLIENT_INFO] pClientInfo->Clients[dwNumElements];

    Or just free the LPDHCP_CLIENT_INFO_ARRAY after accessing the LPDHCP_CLIENT_INFO elements?

    In other words, is all the memory for LPDHCP_CLIENT_INFO_ARRAY allocated after making the call to DhcpEnumSubnetClients()? Or when looping through the elements of the LPDHCP_CLIENT_INFO_ARRAY is memory then allocated on heap?

    -Russ



    Sunday, August 4, 2019 9:53 AM

All replies

  • Yes, and in that code. The code disposes all the elements after use of the Client Info Array.

    This requires an additional method to call. I don't like that.

    I would like to dispose of the elements just after accessing them, using a try {finally}.

    When I use dhcpRpcFreememory(), it causes memory access error.

    This is why I asked the question. Sending a link to that source code does not help me.

    Again, I ask:

    Do I need to free each individual element  in [LPDHCP_CLIENT_INFO] pClientInfo->Clients[dwNumElements];

    Or just free the LPDHCP_CLIENT_INFO_ARRAY after accessing the LPDHCP_CLIENT_INFO elements?

    In other words, is all the memory for LPDHCP_CLIENT_INFO_ARRAY allocated after making the call to DhcpEnumSubnetClients()? Or when looping through the elements of the LPDHCP_CLIENT_INFO_ARRAY is memory then allocated on heap?

    Tuesday, August 6, 2019 9:32 PM
  • Hello,

    Thank you for posting here.

    >>When I use dhcpRpcFreememory(), it causes memory access error.

    I'm sorry I can't give you a definite answer about the follow question you ask. There are many possible reasons for this error, so I can only speculate whether it might be caused by you deleting the same memory block twice, or the adress you free do not exist. You didn't tell about what the dhcpRpcFreememory() released.

    I wonder if you can provide a demo that can restore this error, which will help us understand your problem better.

    Best Regards,

    Suarez Zhou


    • Edited by Suarez-Zhou Wednesday, August 7, 2019 9:07 AM
    Wednesday, August 7, 2019 8:49 AM