Resource leak: connectfd in another file
@@ -81,7 +81,7 @@ BOAT_RESULT BoatSignature( const BoatSignatureAlgType type, const BUINT8* prikey
BUINT8 sig[64];
// BUINT8 ecdsPrefix = 0;
- BOAT_RESULT result;
+ BOAT_RESULT result = BOAT_ERROR;
//boat_try_declare;
(void)rsvd;
@@ -368,7 +368,7 @@ BSINT32 BoatConnect(const BCHAR *address, void* rsvd)
return -1;
}
- if( (connectfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 )
+ if( (connectfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
{
BoatLog( BOAT_LOG_CRITICAL, "socket() error" );
return -1;
@@ -383,16 +383,20 @@ BSINT32 BoatConnect(const BCHAR *address, void* rsvd)
server.sin_port = htons(atoi(port));
server.sin_addr = *((struct in_addr *)(he->h_addr_list[0]));
- if(connect(connectfd, (struct sockaddr *)&server,sizeof(struct sockaddr)) == -1)
+ if(connect(connectfd, (struct sockaddr *)&server,sizeof(struct sockaddr)) < 0)
{
BoatLog( BOAT_LOG_CRITICAL, "connect() error" );
+ close(connectfd);
return -1;
}
- if(0 != getsockname(connectfd, &localaddr, &addrlen) )
+ if(getsockname(connectfd, &localaddr, &addrlen) < 0)
{
BoatLog( BOAT_LOG_CRITICAL, "getsockname() error" );
+ close(connectfd);
return -1;
- }else{
+ }
+ else
+ {
localaddr_ptr = (struct sockaddr_in*)&localaddr;
BoatLog(BOAT_LOG_VERBOSE, "localIP: %s:%d.",
inet_ntoa(localaddr_ptr->sin_addr), htons(localaddr_ptr->sin_port));
