[ 
https://issues.apache.org/jira/browse/THRIFT-1201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13758258#comment-13758258
 ] 

Ben Craig commented on THRIFT-1201:
-----------------------------------

RE: where to put this
There's the easy way, and there's the "right" way.

The easy way is to make this an inline, non-member function in TSocket.h, and 
to change TServerSocket to #include TSocket.h instead of forward declaring 
TSocket.

The right way is to add a new header and cpp file to house this function, and 
possibly other socket helper functions.

General commentary:
A shared_ptr works, but isn't ideal for this situation.  The ownership of this 
object isn't shared, it is tightly scoped.  Using a shared_ptr also incurs an 
extra heap allocation.  My preference (but a weak preference) is to just make a 
struct with a public addrinfo* member, and a destructor that calls 
freeaddrinfo.  That being said, I would still be willing to submit a patch with 
a shared_ptr implementation.

If you stick with a shared_ptr implementation, then I think you can get rid of 
the AddrInfoDeleter struct, and just pass in &::freeaddrinfo.  Function 
pointers are legal deleters, so long as they have a compatible signature.  I 
don't have a strong preference on this item either though.
                
> getaddrinfo resource leak
> -------------------------
>
>                 Key: THRIFT-1201
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1201
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.6.1
>            Reporter: Craig Robson
>            Priority: Minor
>         Attachments: THRIFT-1201.patch
>
>
> TServerSocket::listen() calls getaddrinfo().  There are several ways 
> exceptions can happen before freeaddrinfo() is called thus leaking the 
> getaddrinfo result.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to