Fix a variety of scan-build warnings.

This commit is contained in:
Roger A. Light 2019-03-26 14:00:42 +00:00
parent 67707b819d
commit 9faad1e078
8 changed files with 18 additions and 24 deletions

View File

@ -758,7 +758,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
char *key; char *key;
struct mosquitto__listener *cur_listener = &config->default_listener; struct mosquitto__listener *cur_listener = &config->default_listener;
int i; int i;
int lineno_ext; int lineno_ext = 0;
*lineno = 0; *lineno = 0;

View File

@ -444,7 +444,6 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}else if(rc == MOSQ_ERR_PROTOCOL){ }else if(rc == MOSQ_ERR_PROTOCOL){
if(context->protocol == mosq_p_mqtt31){ if(context->protocol == mosq_p_mqtt31){
/* Password flag given, but no password. Ignore. */ /* Password flag given, but no password. Ignore. */
password_flag = 0;
}else{ }else{
rc = MOSQ_ERR_PROTOCOL; rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error; goto handle_connect_error;
@ -480,7 +479,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
} }
#ifdef WITH_TLS #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 */ /* Don't need the username or password if provided */
mosquitto__free(username); mosquitto__free(username);
username = NULL; username = NULL;
@ -615,7 +614,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
} }
#endif #endif
if(context->listener && context->listener->use_username_as_clientid){ if(context->listener->use_username_as_clientid){
if(context->username){ if(context->username){
mosquitto__free(client_id); mosquitto__free(client_id);
client_id = mosquitto__strdup(context->username); client_id = mosquitto__strdup(context->username);

View File

@ -110,7 +110,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
time_t last_backup = mosquitto_time(); time_t last_backup = mosquitto_time();
#endif #endif
time_t now = 0; time_t now = 0;
time_t now_time;
int time_count; int time_count;
int fdcount; int fdcount;
struct mosquitto *context, *ctxt_tmp; struct mosquitto *context, *ctxt_tmp;
@ -216,8 +215,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
} }
#endif #endif
now_time = time(NULL);
time_count = 0; time_count = 0;
HASH_ITER(hh_sock, db->contexts_by_sock, context, ctxt_tmp){ HASH_ITER(hh_sock, db->contexts_by_sock, context, ctxt_tmp){
if(time_count > 0){ if(time_count > 0){
@ -469,8 +466,8 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
} }
} }
#endif #endif
now_time = time(NULL); now = time(NULL);
if(db->config->persistent_client_expiration > 0 && now_time > expiration_check_time){ if(db->config->persistent_client_expiration > 0 && now > expiration_check_time){
HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){ 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){ 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 /* 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, * persistent_client_expiration seconds ago. If so,
* expire it and clean up. * expire it and clean up.
*/ */
if(now_time > context->session_expiry_time){ if(now > context->session_expiry_time){
if(context->id){ if(context->id){
id = context->id; id = context->id;
}else{ }else{

View File

@ -527,7 +527,10 @@ int main(int argc, char *argv[])
if(create_new){ if(create_new){
rc = get_password(password, 1024); rc = get_password(password, 1024);
if(rc) return rc; if(rc){
free(password_file);
return rc;
}
fptr = fopen(password_file, "wt"); fptr = fopen(password_file, "wt");
if(!fptr){ if(!fptr){
fprintf(stderr, "Error: Unable to open file %s for writing. %s.\n", password_file, strerror(errno)); fprintf(stderr, "Error: Unable to open file %s for writing. %s.\n", password_file, strerror(errno));

View File

@ -666,6 +666,7 @@ int net__socket_get_address(mosq_sock_t sock, char *buf, int len)
struct sockaddr_storage addr; struct sockaddr_storage addr;
socklen_t addrlen; socklen_t addrlen;
memset(&addr, 0, sizeof(struct sockaddr_storage));
addrlen = sizeof(addr); addrlen = sizeof(addr);
if(!getpeername(sock, (struct sockaddr *)&addr, &addrlen)){ if(!getpeername(sock, (struct sockaddr *)&addr, &addrlen)){
if(addr.ss_family == AF_INET){ if(addr.ss_family == AF_INET){

View File

@ -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.topic, chunk.F.qos, chunk.F.payloadlen,
&chunk.payload, chunk.F.retain, &stored, message_expiry_interval, chunk.properties, chunk.F.store_id); &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.id);
mosquitto__free(chunk.source.username); mosquitto__free(chunk.source.username);
chunk.source.id = NULL; chunk.source.id = NULL;
chunk.source.username = NULL; chunk.source.username = NULL;
if(rc == MOSQ_ERR_SUCCESS){ if(rc == MOSQ_ERR_SUCCESS){
stored->source_listener = chunk.source.listener;
load->db_id = stored->db_id; load->db_id = stored->db_id;
load->store = stored; load->store = stored;

View File

@ -131,6 +131,8 @@ int persist__chunk_msg_store_read_v5(FILE *db_fptr, struct P_msg_store *chunk, u
mosquitto_property *properties = NULL; mosquitto_property *properties = NULL;
struct mosquitto__packet prop_packet; struct mosquitto__packet prop_packet;
memset(&prop_packet, 0, sizeof(struct mosquitto__packet));
read_e(db_fptr, &chunk->F, sizeof(struct PF_msg_store)); read_e(db_fptr, &chunk->F, sizeof(struct PF_msg_store));
chunk->F.payloadlen = ntohl(chunk->F.payloadlen); chunk->F.payloadlen = ntohl(chunk->F.payloadlen);
chunk->F.source_mid = ntohs(chunk->F.source_mid); 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){ if(length > 0){
memset(&prop_packet, 0, sizeof(struct mosquitto__packet));
prop_packet.remaining_length = length; prop_packet.remaining_length = length;
prop_packet.payload = mosquitto__malloc(length); prop_packet.payload = mosquitto__malloc(length);
if(!prop_packet.payload){ if(!prop_packet.payload){

View File

@ -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; leaf = hier->subs;
while(source_id && leaf){ 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 = leaf->next;
} }
leaf = mosquitto__malloc(sizeof(struct mosquitto__subleaf)); leaf = mosquitto__calloc(1, sizeof(struct mosquitto__subleaf));
if(!leaf) return MOSQ_ERR_NOMEM; if(!leaf) return MOSQ_ERR_NOMEM;
leaf->next = NULL;
leaf->context = context; leaf->context = context;
leaf->qos = qos; leaf->qos = qos;
leaf->identifier = identifier; 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) 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; struct mosquitto__subhier **subs;
int i; int i;
int rc; int rc;
@ -668,7 +667,7 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
assert(sibling); assert(sibling);
child = mosquitto__malloc(sizeof(struct mosquitto__subhier)); child = mosquitto__calloc(1, sizeof(struct mosquitto__subhier));
if(!child){ if(!child){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return NULL; return NULL;
@ -684,10 +683,6 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
}else{ }else{
strncpy(child->topic, topic, child->topic_len+1); 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); HASH_ADD_KEYPTR(hh, *sibling, child->topic, child->topic_len, child);