Skip to content

Commit

Permalink
Merge pull request #82 from davidvossel/master
Browse files Browse the repository at this point in the history
coverity fixes
  • Loading branch information
davidvossel committed Jul 22, 2013
2 parents 39e9ef5 + a78526a commit f533b97
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/ipcclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void
_benchmark(qb_ipcc_connection_t *conn, int write_size)
{
struct iovec iov[2];
unsigned int res;
ssize_t res;
struct qb_ipc_request_header hdr;
int write_count = 0;
float secs;
Expand Down
5 changes: 4 additions & 1 deletion examples/tcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ sock_read_fn(int32_t fd, int32_t revents, void *data)
} else {
printf("Recieved: %s\n", recv_data);
snprintf(send_data, 1024, "ACK %d bytes", bytes_recieved);
send(fd, send_data, strlen(send_data), 0);
if (send(fd, send_data, strlen(send_data), 0) < 0) {
close(fd);
return QB_FALSE;
}
}
return QB_TRUE;
}
Expand Down
1 change: 0 additions & 1 deletion lib/ipc_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ int32_t qb_ipcs_us_withdraw(struct qb_ipcs_service *s);
int32_t qb_ipcc_us_sock_connect(const char *socket_name, int32_t * sock_pt);

int32_t qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents, void *data);
int32_t qb_ipcs_dispatch_service_request(int32_t fd, int32_t revents, void *data);
struct qb_ipcs_connection* qb_ipcs_connection_alloc(struct qb_ipcs_service *s);

int32_t qb_ipcs_process_request(struct qb_ipcs_service *s,
Expand Down
2 changes: 1 addition & 1 deletion lib/ipc_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ qb_ipcs_shm_disconnect(struct qb_ipcs_connection *c)
if (c->setup.u.us.sock > 0) {
qb_ipcc_us_sock_close(c->setup.u.us.sock);
(void)c->service->poll_fns.dispatch_del(c->setup.u.us.sock);
qb_ipcs_connection_unref(c);
c->setup.u.us.sock = -1;
qb_ipcs_connection_unref(c);
}
}
if (c->state == QB_IPCS_CONNECTION_SHUTTING_DOWN ||
Expand Down
10 changes: 8 additions & 2 deletions lib/ipc_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ qb_ipcc_us_connect(struct qb_ipcc_connection * c,
c->event.u.us.shared_data = shm_ptr + (2 * sizeof(struct ipc_us_control));

close(fd_hdr);
fd_hdr = -1;

res = qb_ipc_dgram_sock_connect(r->response, "response", "request",
r->max_msg_size, &c->request.u.us.sock);
Expand All @@ -418,7 +419,9 @@ qb_ipcc_us_connect(struct qb_ipcc_connection * c,
return 0;

cleanup_hdr:
close(fd_hdr);
if (fd_hdr >= 0) {
close(fd_hdr);
}
close(c->event.u.us.sock);
close(c->request.u.us.sock);
unlink(r->request);
Expand Down Expand Up @@ -583,6 +586,7 @@ qb_ipcs_us_connect(struct qb_ipcs_service *s,
ctl->flow_control = 0;

close(fd_hdr);
fd_hdr = -1;

/* request channel */
res = qb_ipc_dgram_sock_setup(r->response, "request",
Expand Down Expand Up @@ -618,7 +622,9 @@ qb_ipcs_us_connect(struct qb_ipcs_service *s,
free(c->response.u.us.sock_name);
free(c->event.u.us.sock_name);

close(fd_hdr);
if (fd_hdr >= 0) {
close(fd_hdr);
}
unlink(r->request);
munmap(c->request.u.us.shared_data, SHM_CONTROL_SIZE);
return res;
Expand Down
19 changes: 6 additions & 13 deletions lib/ipcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,8 @@ _process_request_(struct qb_ipcs_connection *c, int32_t ms_timeout)
} else if (size == 0 || hdr->id == QB_IPC_MSG_DISCONNECT) {
qb_util_log(LOG_DEBUG, "client requesting a disconnect (%s)",
c->description);
qb_ipcs_disconnect(c);
c = NULL;
res = -ESHUTDOWN;
goto cleanup;
} else {
c->stats.requests++;
res = c->service->serv_fns.msg_process(c, hdr, hdr->size);
Expand All @@ -717,17 +716,6 @@ _process_request_(struct qb_ipcs_connection *c, int32_t ms_timeout)
#define IPC_REQUEST_TIMEOUT 10
#define MAX_RECV_MSGS 50

int32_t
qb_ipcs_dispatch_service_request(int32_t fd, int32_t revents, void *data)
{
int32_t res = _process_request_((struct qb_ipcs_connection *)data,
IPC_REQUEST_TIMEOUT);
if (res > 0) {
return 0;
}
return res;
}

static ssize_t
_request_q_len_get(struct qb_ipcs_connection *c)
{
Expand Down Expand Up @@ -811,6 +799,11 @@ qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents, void *data)

do {
res = _process_request_(c, IPC_REQUEST_TIMEOUT);

if (res == -ESHUTDOWN) {
goto dispatch_cleanup;
}

if (res > 0 || res == -ENOBUFS || res == -EINVAL) {
recvd++;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/log_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ qb_log_thread_stop(void)
for (;;) {
res = sem_getvalue(&logt_print_finished, &value);
if (res != 0 || value == 0) {
return;
break;
}
sem_wait(&logt_print_finished);

Expand Down
3 changes: 1 addition & 2 deletions lib/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ qb_rb_open_2(const char *name, size_t size, uint32_t flags,
"shm size:%zd; real_size:%zd; rb->word_size:%d", size,
real_size, rb->shared_hdr->word_size);

/* this function closes fd_data */
error = qb_sys_circular_mmap(fd_data, &shm_addr, real_size);
rb->shared_data = shm_addr;
if (error != 0) {
Expand All @@ -252,11 +253,9 @@ qb_rb_open_2(const char *name, size_t size, uint32_t flags,
}

close(fd_hdr);
close(fd_data);
return rb;

cleanup_data:
close(fd_data);
if (flags & QB_RB_FLAG_CREATE) {
unlink(rb->shared_hdr->data_path);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ qb_sys_mmap_file_open(char *path, const char *file, size_t bytes,

unlink_exit:
unlink(path);
if (fd > 0) {
if (fd >= 0) {
close(fd);
}
return res;
Expand Down
2 changes: 2 additions & 0 deletions tests/bms.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c,
sizeof(response));
if (res < 0) {
qb_perror(LOG_ERR, "qb_ipcs_response_send");
return res;
}
}
if (events) {
res = qb_ipcs_event_send(c, &response,
sizeof(response));
if (res < 0) {
qb_perror(LOG_ERR, "qb_ipcs_event_send");
return res;
}
}
return 0;
Expand Down

0 comments on commit f533b97

Please sign in to comment.