Skip to content
This repository was archived by the owner on Nov 8, 2025. It is now read-only.
This repository was archived by the owner on Nov 8, 2025. It is now read-only.

内存泄漏的问题 #19

@HuYuHua

Description

@HuYuHua

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); 会导致内存泄漏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions