diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 58815596ea2..991ba4894c2 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -3315,7 +3315,7 @@ static void async_callback(struct ctdb_client_control_state *state) struct ctdb_context *ctdb = talloc_get_type(state->ctdb, struct ctdb_context); int ret; TDB_DATA outdata; - int32_t res; + int32_t res = -1; uint32_t destnode = state->c->hdr.destnode; /* one more node has responded with recmode data */ diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c index 990a6b558c9..ba3e8610c5d 100644 --- a/ctdb/common/ctdb_logging.c +++ b/ctdb/common/ctdb_logging.c @@ -129,7 +129,7 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a tm = localtime(&log_entries[tmp_entry].t.tv_sec); strftime(tbuf, sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm); - if (log_entries[tmp_entry].message) { + if (log_entries[tmp_entry].message[0] != '\0') { fprintf(f, "%s:%s %s", tbuf, get_debug_by_level(log_entries[tmp_entry].level), log_entries[tmp_entry].message); @@ -137,9 +137,17 @@ void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_a } fsize = ftell(f); + if (fsize < 0) { + fclose(f); + DEBUG(DEBUG_ERR, ("Cannot get file size for log entries\n")); + return; + } rewind(f); data.dptr = talloc_size(NULL, fsize); - CTDB_NO_MEMORY_VOID(ctdb, data.dptr); + if (data.dptr == NULL) { + fclose(f); + CTDB_NO_MEMORY_VOID(ctdb, data.dptr); + } data.dsize = fread(data.dptr, 1, fsize, f); fclose(f); diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index cc09346c236..0932157cf87 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -1273,6 +1273,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog, fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, EVENT_FD_READ, ctdb_accept_client, ctdb); + if (fde == NULL) { + ctdb_fatal(ctdb, "Failed to add daemon socket to event loop"); + } tevent_fd_set_auto_close(fde); /* release any IPs we hold from previous runs of the daemon */ diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index adf1c8f2ba6..218186e7f04 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -547,6 +547,10 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb) /* We'll fail if stderr/stdout not already open; it's simpler. */ old_stdout = dup(STDOUT_FILENO); old_stderr = dup(STDERR_FILENO); + if (old_stdout < 0 || old_stderr < 0) { + DEBUG(DEBUG_ERR, ("Failed to dup stdout/stderr for child logging\n")); + return -1; + } if (dup2(p[1], STDOUT_FILENO) < 0 || dup2(p[1], STDERR_FILENO) < 0) { int saved_errno = errno; dup2(old_stdout, STDOUT_FILENO); diff --git a/ctdb/server/ctdb_ltdb_server.c b/ctdb/server/ctdb_ltdb_server.c index 6b27e290c9e..57e0d68b71d 100644 --- a/ctdb/server/ctdb_ltdb_server.c +++ b/ctdb/server/ctdb_ltdb_server.c @@ -1187,7 +1187,10 @@ static int ctdb_attach_persistent(struct ctdb_context *ctdb, int invalid_name = 0; s = talloc_strdup(ctdb, de->d_name); - CTDB_NO_MEMORY(ctdb, s); + if (s == NULL) { + closedir(d); + CTDB_NO_MEMORY(ctdb, s); + } /* only accept names ending in .tdb */ p = strstr(s, ".tdb."); diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 5a6055c6c1f..93587341437 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -1260,8 +1260,8 @@ static int traverse_recdb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, params->recdata = talloc_realloc_size(NULL, params->recdata, params->allocated_len); } if (params->recdata == NULL) { - DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u (%u records)\n", - rec->length + params->len, params->recdata->count)); + DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u\n", + rec->length + params->len)); params->failed = true; return -1; } diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 1152319b039..10d426fba7f 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -218,6 +218,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb, tree_item = talloc(tree, struct ctdb_script_tree_item); if (tree_item == NULL) { DEBUG(DEBUG_ERR, (__location__ " Failed to allocate new tree item\n")); + closedir(dir); talloc_free(tmp_ctx); return NULL; } @@ -230,6 +231,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb, tree_item->name = talloc_strdup(tree_item, de->d_name); if (tree_item->name == NULL) { DEBUG(DEBUG_ERR,(__location__ " Failed to allocate script name.\n")); + closedir(dir); talloc_free(tmp_ctx); return NULL; } @@ -880,10 +882,10 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call va_start(ap, fmt); ret = ctdb_event_script_callback_v(ctdb, ctdb, event_script_callback, &status, false, call, fmt, ap); + va_end(ap); if (ret != 0) { return ret; } - va_end(ap); status.status = -1; status.done = false; diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c index e8cae58bd6f..383d72641b2 100644 --- a/ctdb/tcp/tcp_connect.c +++ b/ctdb/tcp/tcp_connect.c @@ -154,6 +154,10 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te, } tnode->fd = socket(sock_out.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); + if (tnode->fd == -1) { + DEBUG(DEBUG_ERR, (__location__ "Failed to create socket\n")); + return; + } set_nonblocking(tnode->fd); set_close_on_exec(tnode->fd); @@ -196,7 +200,12 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te, sock_in.ip.sin_len = sockin_size; sock_out.ip.sin_len = sockout_size; #endif - bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size); + if (bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size) == -1) { + DEBUG(DEBUG_ERR, (__location__ "Failed to bind socket %s(%d)\n", + strerror(errno), errno)); + close(tnode->fd); + return; + } if (connect(tnode->fd, (struct sockaddr *)&sock_out, sockout_size) != 0 && errno != EINPROGRESS) { diff --git a/ctdb/tests/src/ctdb_fetch.c b/ctdb/tests/src/ctdb_fetch.c index db84f5d5c4e..b900efa7c3c 100644 --- a/ctdb/tests/src/ctdb_fetch.c +++ b/ctdb/tests/src/ctdb_fetch.c @@ -83,6 +83,11 @@ static void bench_fetch_1node(struct ctdb_context *ctdb) data.dptr = (uint8_t *)talloc_asprintf_append((char *)data.dptr, "msg_count=%d on node %d\n", msg_count, ctdb_get_pnn(ctdb)); + if (data.dptr == NULL) { + printf("Failed to create record\n"); + talloc_free(tmp_ctx); + return; + } data.dsize = strlen((const char *)data.dptr)+1; ret = ctdb_record_store(h, data);