Fix a variety of scan-build warnings.
This commit is contained in:
parent
67707b819d
commit
9faad1e078
@ -758,7 +758,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
|
||||
char *key;
|
||||
struct mosquitto__listener *cur_listener = &config->default_listener;
|
||||
int i;
|
||||
int lineno_ext;
|
||||
int lineno_ext = 0;
|
||||
|
||||
*lineno = 0;
|
||||
|
||||
|
@ -444,7 +444,6 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}else if(rc == MOSQ_ERR_PROTOCOL){
|
||||
if(context->protocol == mosq_p_mqtt31){
|
||||
/* Password flag given, but no password. Ignore. */
|
||||
password_flag = 0;
|
||||
}else{
|
||||
rc = MOSQ_ERR_PROTOCOL;
|
||||
goto handle_connect_error;
|
||||
@ -480,7 +479,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}
|
||||
|
||||
#ifdef WITH_TLS
|
||||
if(context->listener && context->listener->ssl_ctx && (context->listener->use_identity_as_username || context->listener->use_subject_as_username)){
|
||||
if(context->listener->ssl_ctx && (context->listener->use_identity_as_username || context->listener->use_subject_as_username)){
|
||||
/* Don't need the username or password if provided */
|
||||
mosquitto__free(username);
|
||||
username = NULL;
|
||||
@ -615,7 +614,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}
|
||||
#endif
|
||||
|
||||
if(context->listener && context->listener->use_username_as_clientid){
|
||||
if(context->listener->use_username_as_clientid){
|
||||
if(context->username){
|
||||
mosquitto__free(client_id);
|
||||
client_id = mosquitto__strdup(context->username);
|
||||
|
@ -110,7 +110,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
|
||||
time_t last_backup = mosquitto_time();
|
||||
#endif
|
||||
time_t now = 0;
|
||||
time_t now_time;
|
||||
int time_count;
|
||||
int fdcount;
|
||||
struct mosquitto *context, *ctxt_tmp;
|
||||
@ -216,8 +215,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
|
||||
}
|
||||
#endif
|
||||
|
||||
now_time = time(NULL);
|
||||
|
||||
time_count = 0;
|
||||
HASH_ITER(hh_sock, db->contexts_by_sock, context, ctxt_tmp){
|
||||
if(time_count > 0){
|
||||
@ -469,8 +466,8 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
|
||||
}
|
||||
}
|
||||
#endif
|
||||
now_time = time(NULL);
|
||||
if(db->config->persistent_client_expiration > 0 && now_time > expiration_check_time){
|
||||
now = time(NULL);
|
||||
if(db->config->persistent_client_expiration > 0 && now > expiration_check_time){
|
||||
HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){
|
||||
if(context->sock == INVALID_SOCKET && context->session_expiry_interval > 0 && context->session_expiry_interval != UINT32_MAX){
|
||||
/* This is a persistent client, check to see if the
|
||||
@ -478,7 +475,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
|
||||
* persistent_client_expiration seconds ago. If so,
|
||||
* expire it and clean up.
|
||||
*/
|
||||
if(now_time > context->session_expiry_time){
|
||||
if(now > context->session_expiry_time){
|
||||
if(context->id){
|
||||
id = context->id;
|
||||
}else{
|
||||
|
@ -527,7 +527,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
if(create_new){
|
||||
rc = get_password(password, 1024);
|
||||
if(rc) return rc;
|
||||
if(rc){
|
||||
free(password_file);
|
||||
return rc;
|
||||
}
|
||||
fptr = fopen(password_file, "wt");
|
||||
if(!fptr){
|
||||
fprintf(stderr, "Error: Unable to open file %s for writing. %s.\n", password_file, strerror(errno));
|
||||
|
@ -666,6 +666,7 @@ int net__socket_get_address(mosq_sock_t sock, char *buf, int len)
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
|
||||
memset(&addr, 0, sizeof(struct sockaddr_storage));
|
||||
addrlen = sizeof(addr);
|
||||
if(!getpeername(sock, (struct sockaddr *)&addr, &addrlen)){
|
||||
if(addr.ss_family == AF_INET){
|
||||
|
@ -271,15 +271,13 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp
|
||||
chunk.topic, chunk.F.qos, chunk.F.payloadlen,
|
||||
&chunk.payload, chunk.F.retain, &stored, message_expiry_interval, chunk.properties, chunk.F.store_id);
|
||||
|
||||
if(stored){
|
||||
stored->source_listener = chunk.source.listener;
|
||||
}
|
||||
mosquitto__free(chunk.source.id);
|
||||
mosquitto__free(chunk.source.username);
|
||||
chunk.source.id = NULL;
|
||||
chunk.source.username = NULL;
|
||||
|
||||
if(rc == MOSQ_ERR_SUCCESS){
|
||||
stored->source_listener = chunk.source.listener;
|
||||
load->db_id = stored->db_id;
|
||||
load->store = stored;
|
||||
|
||||
|
@ -131,6 +131,8 @@ int persist__chunk_msg_store_read_v5(FILE *db_fptr, struct P_msg_store *chunk, u
|
||||
mosquitto_property *properties = NULL;
|
||||
struct mosquitto__packet prop_packet;
|
||||
|
||||
memset(&prop_packet, 0, sizeof(struct mosquitto__packet));
|
||||
|
||||
read_e(db_fptr, &chunk->F, sizeof(struct PF_msg_store));
|
||||
chunk->F.payloadlen = ntohl(chunk->F.payloadlen);
|
||||
chunk->F.source_mid = ntohs(chunk->F.source_mid);
|
||||
@ -179,7 +181,6 @@ int persist__chunk_msg_store_read_v5(FILE *db_fptr, struct P_msg_store *chunk, u
|
||||
}
|
||||
|
||||
if(length > 0){
|
||||
memset(&prop_packet, 0, sizeof(struct mosquitto__packet));
|
||||
prop_packet.remaining_length = length;
|
||||
prop_packet.payload = mosquitto__malloc(length);
|
||||
if(!prop_packet.payload){
|
||||
|
13
src/subs.c
13
src/subs.c
@ -162,7 +162,7 @@ static int subs__process(struct mosquitto_db *db, struct mosquitto__subhier *hie
|
||||
}
|
||||
}
|
||||
|
||||
rc2 = subs__shared_process(db, hier, topic, qos, retain, stored);
|
||||
rc = subs__shared_process(db, hier, topic, qos, retain, stored);
|
||||
|
||||
leaf = hier->subs;
|
||||
while(source_id && leaf){
|
||||
@ -307,9 +307,8 @@ static int sub__add_leaf(struct mosquitto *context, int qos, uint32_t identifier
|
||||
}
|
||||
leaf = leaf->next;
|
||||
}
|
||||
leaf = mosquitto__malloc(sizeof(struct mosquitto__subleaf));
|
||||
leaf = mosquitto__calloc(1, sizeof(struct mosquitto__subleaf));
|
||||
if(!leaf) return MOSQ_ERR_NOMEM;
|
||||
leaf->next = NULL;
|
||||
leaf->context = context;
|
||||
leaf->qos = qos;
|
||||
leaf->identifier = identifier;
|
||||
@ -413,7 +412,7 @@ static int sub__add_shared(struct mosquitto_db *db, struct mosquitto *context, i
|
||||
|
||||
static int sub__add_normal(struct mosquitto_db *db, struct mosquitto *context, int qos, uint32_t identifier, int options, struct mosquitto__subhier *subhier)
|
||||
{
|
||||
struct mosquitto__subleaf *newleaf;
|
||||
struct mosquitto__subleaf *newleaf = NULL;
|
||||
struct mosquitto__subhier **subs;
|
||||
int i;
|
||||
int rc;
|
||||
@ -668,7 +667,7 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
|
||||
|
||||
assert(sibling);
|
||||
|
||||
child = mosquitto__malloc(sizeof(struct mosquitto__subhier));
|
||||
child = mosquitto__calloc(1, sizeof(struct mosquitto__subhier));
|
||||
if(!child){
|
||||
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
|
||||
return NULL;
|
||||
@ -684,10 +683,6 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
|
||||
}else{
|
||||
strncpy(child->topic, topic, child->topic_len+1);
|
||||
}
|
||||
child->subs = NULL;
|
||||
child->shared = NULL;
|
||||
child->children = NULL;
|
||||
child->retained = NULL;
|
||||
|
||||
HASH_ADD_KEYPTR(hh, *sibling, child->topic, child->topic_len, child);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user