重复调用WSALookupServiceBegin时发生内存泄漏

重复调用WSALookupServiceBegin时发生内存泄漏

本文介绍了重复调用WSALookupServiceBegin时发生内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这小段简单的代码出现,表明在用于搜索蓝牙设备时WASLookupServiceBegin中存在内存泄漏.如果您运行代码并监视"Mem Usage",在任务管理器中,该值增加.同样,如果您监视私有字节"

此代码是使用VS 2008编译的.是否有人遇到过这个问题,或者有人可以建议我的代码示例在哪里不正确.

WSAQUERYSET querySet;

内存集(& querySet,0,sizeof(querySet));
querySet.dwSize = sizeof(querySet);
querySet. dwNameSpace = NS_BTH;

HANDLE hLookup;
DWORD标志= LUP_CONTAINERS;

for(int loop = 0; loop< 32766; loop ++)
{
     int result = WSALookupServiceBegin(& querySet,flags& hLookup);

     如果(0 ==结果)
{
       printf("WSALookupServiceBegin()-好的循环:%d \ n",循环);            
      结果= WSALookupServiceEnd(hLookup);
     }
    其他
     {
       printf("WSALookupServiceBegin()-错误:%s.循环:%d \ n",GetLastErrorMessage(GetLastError()),循环);
}
}

解决方案


我从未使用过上述API,但在阅读MSDN上的文档时,我的理解是您应该调用来启动查询.

This small simple piece of code appears to show there is a memory leak in the WASLookupServiceBegin when used for searching for a Bluetooth Device. If you run the code and monitor the "Mem Usage" in Task Manager the value increases. Similarly if you monitors "Private Bytes" for the process the pegged value increases.

This code was compiled using VS 2008. Has anyone else come across this or could someone possibly advise where my code sample is incorrect.

WSAQUERYSET querySet;

memset(&querySet, 0, sizeof(querySet));
querySet.dwSize = sizeof(querySet);
querySet.dwNameSpace = NS_BTH;

HANDLE hLookup;
DWORD flags = LUP_CONTAINERS;

for (int loop =0; loop < 32766; loop++)
{
      int result = WSALookupServiceBegin(&querySet, flags, &hLookup);

      if (0 == result)
      {
        printf("WSALookupServiceBegin() - ok. Loop: %d\n", loop);              
        result = WSALookupServiceEnd(hLookup);
      }
      else
      {
        printf("WSALookupServiceBegin() - Error: %s. Loop: %d\n", GetLastErrorMessage(GetLastError()), loop);
      }
}

解决方案


I've never used the aforementioned APIs, but reading the documentation on MSDN, my understanding is that you should call WSALookupServiceBegin to initiate a query. 


这篇关于重复调用WSALookupServiceBegin时发生内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:19