close resources in DcmTCPConnection destructor

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Shaeto
Posts: 147
Joined: Tue, 2009-01-20, 17:50
Location: CA, USA
Contact:

close resources in DcmTCPConnection destructor

#1 Post by Shaeto »

i didn't find this fix in latest snapshot:

dcmnet/libsrc/dcmtrans.cc

DcmTCPConnection::~DcmTCPConnection()
{
+ close();
}

very bad leak for daemon application

Shaeto
Posts: 147
Joined: Tue, 2009-01-20, 17:50
Location: CA, USA
Contact:

#2 Post by Shaeto »

forget about ::close - if we'll add close in destructor also need to add those changes:

dcmtrans.h

int getSocket() { return theSocket; }
+ void setSocket(int socket) { theSocket = socket; }

dcmtrans.cc

void DcmTCPConnection::close()
{
+ if (getSocket()>=0) {
#ifdef HAVE_WINSOCK_H
- (void) shutdown(getSocket(), 1 /* SD_SEND */);
- (void) closesocket(getSocket());
+ (void) shutdown(getSocket(), 1 /* SD_SEND */);
+ (void) closesocket(getSocket());
#else
- (void) ::close(getSocket());
+ (void) ::close(getSocket());
#endif
+ setSocket(-1);
+ }
}

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#3 Post by Jörg Riesmeier »

Thank you for the report. We'll check this issue ...

However, closing the socket in the destructor of DcmTCPConnection is probably not a good idea since the socket is not opened within this class.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#4 Post by Jörg Riesmeier »

I checked the code: the invalidation of the socket variable is only required if the connection object exists after the TCP/IP connection has be closed which is currently not the case (see dul.cc and dulfsm.cc)!

Anyway, setting "theSocket" to "-1" after closing the socket is probably still a good idea :-)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest