Don't free a client which hasn't finished yet.

This commit is contained in:
Alex Young
2012-08-23 17:51:19 +01:00
parent c5dfe16f35
commit c3c621f750
3 changed files with 20 additions and 12 deletions

View File

@@ -23,14 +23,13 @@ CCFLAGS = %w(
-Wno-missing-field-initializers
) + # Added -Wno-missing-field-initializers to shut GCC up over {0} struct initialisers
[ENV['CFLAGS']]
LDFLAGS = []
LIBCHECK = "/usr/lib/libcheck.a"
TEST_MODULES = Dir["tests/unit/check_*.c"].map { |n|
File.basename( n )[%r{check_(.+)\.c},1] }
if DEBUG
LDFLAGS << ["-g"]
LDFLAGS << ["-g", "-lefence"]
CCFLAGS << ["-g -DDEBUG"]
end

View File

@@ -32,7 +32,7 @@ struct client *client_create( struct server *serve, int socket )
c->stop_signal = self_pipe_create();
debug( "Alloced client %p (%d, %d)", c, c->stop_signal->read_fd, c->stop_signal->write_fd );
debug( "Alloced client %p with socket %d", c, socket );
return c;
}
@@ -51,6 +51,7 @@ void client_destroy( struct client *client )
debug( "Destroying stop signal for client %p", client );
self_pipe_destroy( client->stop_signal );
debug( "Freeing client %p", client );
free( client );
}
@@ -491,17 +492,21 @@ void client_cleanup(struct client* client,
info("client cleanup for client %p", client);
if (client->socket) {
close(client->socket);
client->socket = -1;
FATAL_IF_NEGATIVE( close(client->socket),
"Error closing client socket %d",
client->socket );
debug("Closed client socket fd %d", client->socket);
client->socket = -1;
}
if (client->mapped) {
munmap(client->mapped, client->serve->size);
}
if (client->fileno) {
close(client->fileno);
client->fileno = -1;
FATAL_IF_NEGATIVE( close(client->fileno),
"Error closing file %d",
client->fileno );
debug("Closed client file fd %d", client->fileno );
client->fileno = -1;
}
if ( server_io_locked( client->serve ) ) { server_unlock_io( client->serve ); }

View File

@@ -342,12 +342,13 @@ int tryjoin_client_thread( struct client_tbl_entry *entry, int (*joinfunc)(pthre
/* join_errno can legitimately be ESRCH if the thread is
* already dead, but the client still needs tidying up. */
if (join_errno != 0 && !entry->client->stopped ) {
debug( "join_errno was %s, stopped was %d", strerror( join_errno ), entry->client->stopped );
FATAL_UNLESS( join_errno == EBUSY,
"Problem with joining thread %p: %s",
entry->thread,
strerror(join_errno) );
}
else {
else if ( join_errno == 0 ) {
debug("nbd thread %016x exited (%s) with status %ld",
entry->thread,
s_client_address,
@@ -504,7 +505,8 @@ void accept_nbd_client(
if ( !server_should_accept_client( params, client_address, s_client_address, 64 ) ) {
close( client_fd );
FATAL_IF_NEGATIVE( close( client_fd ),
"Error closing client socket fd %d", client_fd );
debug("Closed client socket fd %d", client_fd);
return;
}
@@ -512,12 +514,13 @@ void accept_nbd_client(
slot = cleanup_and_find_client_slot(params);
if (slot < 0) {
warn("too many clients to accept connection");
close(client_fd);
FATAL_IF_NEGATIVE( close( client_fd ),
"Error closing client socket fd %d", client_fd );
debug("Closed client socket fd %d", client_fd);
return;
}
info( "Client %s accepted.", s_client_address );
info( "Client %s accepted on fd %d.", s_client_address, client_fd );
client_params = client_create( params, client_fd );
params->nbd_client[slot].client = client_params;
@@ -529,7 +532,8 @@ void accept_nbd_client(
if ( 0 != spawn_client_thread( client_params, thread ) ) {
debug( "Thread creation problem." );
client_destroy( client_params );
close(client_fd);
FATAL_IF_NEGATIVE( close(client_fd),
"Error closing client socket fd %d", client_fd );
debug("Closed client socket fd %d", client_fd);
return;
}