Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

内存泄漏的问题 #19

Open
HuYuHua opened this issue Aug 13, 2018 · 3 comments
Open

内存泄漏的问题 #19

HuYuHua opened this issue Aug 13, 2018 · 3 comments

Comments

@HuYuHua
Copy link

HuYuHua commented Aug 13, 2018

string srs_dns_resolve(string host, int& family)
{
addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = family;

addrinfo* r = NULL; 
SrsAutoFree(addrinfo, r);

if(getaddrinfo(host.c_str(), NULL, NULL, &r)) {
    return "";
}

char saddr[64];
char* h = (char*)saddr;
socklen_t nbh = sizeof(saddr);
const int r0 = getnameinfo(r->ai_addr, r->ai_addrlen, h, nbh, NULL, 0, NI_NUMERICHOST);

if(!r0) {
   family = r->ai_family;
   //freeaddrinfo(r);
   return string(saddr);
}
//freeaddrinfo(r);
return "";

}

这里使用SrsAutoFree(addrinfo, r); 会导致内存泄漏

@winlinvip
Copy link
Member

Why?

@HuYuHua
Copy link
Author

HuYuHua commented Aug 14, 2018

我用valgrind 测试的时候报getaddrinfo申请的内存没有释放。 但我用freeaddrinfo函数就没有报内存泄漏。

@this-cat
Copy link

freeaddrinfo 不就是释放吗?...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants