Skip to content

Commit

Permalink
dcap client: close tunnel when closing control channel
Browse files Browse the repository at this point in the history
The dcap client includes the concept of optionally encoding the control 
channel.  This is enabled through loading a DSO plugin.  In addition to 
the encoding and decoding functions, the plugins also have an 
initialise and destroy functions.

The dcap code calls the initialise method but fails to ever call the 
destroy function of the plugin.  Under certain circumstances this can 
lead to a memory leak.

This patch updates the dcap client so it calls the tunnel's destroy 
function (if a tunnel is being used) when the control channel is 
closed.

FOR RELEASE NOTES:

Mention that a memory leak for gsidcap under rare conditions has been 
fixed.

Target: trunk
Require-notes: yes
Require-book: no
Patch: http://rb.dcache.org/r/5043/
Acked-by: Tigran Mkrtchyan
Require-notes: yes
Require-book: no
  • Loading branch information
paulmillar committed Jan 7, 2013
1 parent dfa6fc5 commit 228ba86
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
19 changes: 15 additions & 4 deletions modules/dcap/src/dcap.c
Expand Up @@ -420,7 +420,7 @@ serverConnect(struct vsp_node * node)
pollDelete(node->fd);

/* file descriptor can be reused by system */
system_close(node->fd);
close_control_socket(node->fd, node->tunnel);
node->fd = -1;
continue;
}
Expand Down Expand Up @@ -733,7 +733,7 @@ cache_connect(server * srv)
setTunnelPair(fd, srv->tunnel);

if( sayHello(fd, srv->tunnel) < 0 ) {
system_close(fd);
close_control_socket(fd, srv->tunnel);
dc_errno = DEHELLO;
return -1;
}
Expand Down Expand Up @@ -1158,9 +1158,20 @@ ascii_open_conversation(struct vsp_node * node)
int
close_data_socket(int dataFd)
{
return system_close(dataFd);
return system_close(dataFd);
}


int close_control_socket(int ctlFd, ioTunnel *tunnel)
{
if(tunnel != NULL) {
tunnel->eDestroy(ctlFd);
}

return system_close(ctlFd);
}


int sendControlMessage(int to, const char *buff, size_t len, ioTunnel *en)
{
int n;
Expand Down Expand Up @@ -1856,7 +1867,7 @@ int newControlLine(struct vsp_node *node)
pollDelete(node->fd);

/* file descriptor can be reused by system */
system_close(node->fd);
close_control_socket(node->fd, node->tunnel);

if ( initControlLine(node) < 0) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/dcap/src/dcap_close.c
Expand Up @@ -191,7 +191,7 @@ dc_close(int fd)
deleteMemberByValue(node->fd);
unlockMember();
pollDelete(node->fd);
system_close(node->fd);
close_control_socket(node->fd, node->tunnel);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/dcap/src/dcap_functions.h
Expand Up @@ -26,6 +26,7 @@

int cache_open(struct vsp_node *);
int close_data_socket(int);
int close_control_socket(int, ioTunnel *);
int sendControlMessage(int, const char *, size_t, ioTunnel *);
asciiMessage *getControlMessage(int, struct vsp_node *);
int data_hello_conversation(struct vsp_node *);
Expand Down
2 changes: 1 addition & 1 deletion modules/dcap/src/dcap_poll.c
Expand Up @@ -253,7 +253,7 @@ dcap_poll(int mode, struct vsp_node *node, int what)

int_pollDelete(node->fd);
/* file descriptor can be reused by system */
system_close(node->fd);
close_control_socket(node->fd, node->tunnel);

break;
case ASCII_CONNECT:
Expand Down

0 comments on commit 228ba86

Please sign in to comment.