Nullcheck *before* dereferencing.

Also bracketing, replacing a lost comment, and some variable naming.
This commit is contained in:
Alex Young
2012-10-08 14:54:10 +01:00
parent a49cf14927
commit cf62b10adf
2 changed files with 17 additions and 11 deletions

View File

@@ -412,6 +412,8 @@ void client_reply_to_write( struct client* client, struct nbd_request request )
} }
else { else {
debug("No allocation map, writing directly."); debug("No allocation map, writing directly.");
/* If we get cut off partway through reading this data:
* */
ERROR_IF_NEGATIVE( ERROR_IF_NEGATIVE(
readloop( client->socket, readloop( client->socket,
client->mapped + request.from, client->mapped + request.from,

View File

@@ -757,20 +757,23 @@ void serve_accept_loop(struct server* params)
while( server_accept( params ) ); while( server_accept( params ) );
} }
void* build_allocation_map_thread(void* params1) void* build_allocation_map_thread(void* serve_uncast)
{ {
struct server* params = (struct server*) params1; NULLCHECK(serve_uncast);
int fd = open(params->filename, O_RDONLY);
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", params->filename);
NULLCHECK(params);
params->allocation_map = bitset_alloc(params->size, struct server* serve = (struct server*) serve_uncast;
block_allocation_resolution); int fd = open(serve->filename, O_RDONLY);
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", serve->filename);
if (build_allocation_map(params->allocation_map, fd)) serve->allocation_map =
params->allocation_map_built = 1; bitset_alloc(serve->size, block_allocation_resolution);
else
warn("Didn't build allocation map for %s", params->filename); if (build_allocation_map(serve->allocation_map, fd)) {
serve->allocation_map_built = 1;
}
else {
warn("Didn't build allocation map for %s", serve->filename);
}
close(fd); close(fd);
return NULL; return NULL;
@@ -805,6 +808,7 @@ void serve_signal_close( struct server * serve )
self_pipe_signal( serve->close_signal ); self_pipe_signal( serve->close_signal );
} }
/* Block until the server closes the server_fd. /* Block until the server closes the server_fd.
*/ */
void serve_wait_for_close( struct server * serve ) void serve_wait_for_close( struct server * serve )