Fix some defects discovered by coverity.

This commit is contained in:
Roger A. Light 2016-03-18 11:54:36 +00:00
parent 70f2bea51f
commit 37dceb38f9
10 changed files with 21 additions and 9 deletions

View File

@ -31,7 +31,6 @@ addons:
project:
name: "eclipse/mosquitto"
description: "Build submitted via Travis CI"
version:
notification_email: roger@atchoo.org
build_command_prepend: ./travis-configure.sh
build_command: "make binary -j 4"

View File

@ -38,7 +38,7 @@ static void write_payload(const unsigned char *payload, int payloadlen, bool hex
int i;
if(!hex){
fwrite(payload, 1, payloadlen, stdout);
(void)fwrite(payload, 1, payloadlen, stdout);
}else{
for(i=0; i<payloadlen; i++){
fprintf(stdout, "%x", payload[i]);

View File

@ -1126,6 +1126,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const
token = strtok_r(NULL, " ", &saveptr);
if(!token){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty include_dir value in configuration.");
return 1;
}
#ifdef WIN32
snprintf(dirpath, MAX_PATH, "%s\\*.conf", token);

View File

@ -527,6 +527,7 @@ int db__messages_easy_queue(struct mosquitto_db *db, struct mosquitto *context,
if(!topic_heap) return MOSQ_ERR_INVAL;
if(UHPA_ALLOC(payload_uhpa, payloadlen) == 0){
mosquitto__free(topic_heap);
return MOSQ_ERR_NOMEM;
}
memcpy(UHPA_ACCESS(payload_uhpa, payloadlen), payload, payloadlen);
@ -552,6 +553,7 @@ int db__message_store(struct mosquitto_db *db, const char *source, uint16_t sour
temp = mosquitto__malloc(sizeof(struct mosquitto_msg_store));
if(!temp){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
rc = MOSQ_ERR_NOMEM;
goto error;
}

View File

@ -128,7 +128,6 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
protocol_version, context->address);
}
send__connack(context, 0, CONNACK_REFUSED_PROTOCOL_VERSION);
mosquitto__free(protocol_name);
rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}
@ -140,13 +139,11 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
protocol_version, context->address);
}
send__connack(context, 0, CONNACK_REFUSED_PROTOCOL_VERSION);
mosquitto__free(protocol_name);
rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}
if((context->in_packet.command&0x0F) != 0x00){
/* Reserved flags not set to 0, must disconnect. */
mosquitto__free(protocol_name);
rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}
@ -156,11 +153,11 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
log__printf(NULL, MOSQ_LOG_INFO, "Invalid protocol \"%s\" in CONNECT from %s.",
protocol_name, context->address);
}
mosquitto__free(protocol_name);
rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}
mosquitto__free(protocol_name);
protocol_name = NULL;
if(packet__read_byte(&context->in_packet, &connect_flags)){
rc = 1;
@ -577,6 +574,7 @@ handle_connect_error:
mosquitto__free(will_payload);
mosquitto__free(will_topic);
mosquitto__free(will_struct);
mosquitto__free(protocol_name);
#ifdef WITH_TLS
if(client_cert) X509_free(client_cert);
#endif

View File

@ -635,16 +635,21 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp
}
rc = db__message_store(db, source_id, source_mid, topic, qos, payloadlen, &payload, retain, &stored, store_id);
mosquitto__free(source_id);
if(rc == MOSQ_ERR_SUCCESS){
load->db_id = stored->db_id;
load->store = stored;
HASH_ADD(hh, db->msg_store_load, db_id, sizeof(dbid_t), load);
return MOSQ_ERR_SUCCESS;
}else{
mosquitto__free(load);
fclose(db_fptr);
mosquitto__free(topic);
UHPA_FREE(payload, payloadlen);
return rc;
}
mosquitto__free(source_id);
return rc;
error:
strerror_r(errno, err, 256);
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err);

View File

@ -188,6 +188,8 @@ int mosquitto_security_module_cleanup(struct mosquitto_db *db)
db->auth_plugins[i].unpwd_check = NULL;
db->auth_plugins[i].psk_key_get = NULL;
}
mosquitto__free(db->auth_plugins);
db->auth_plugins = NULL;
return MOSQ_ERR_SUCCESS;
}

View File

@ -131,6 +131,8 @@ int add__acl(struct mosquitto_db *db, const char *user, const char *topic, int a
acl = mosquitto__malloc(sizeof(struct mosquitto__acl));
if(!acl){
mosquitto__free(local_topic);
mosquitto__free(acl_user->username);
mosquitto__free(acl_user);
return MOSQ_ERR_NOMEM;
}
acl->access = access;

View File

@ -36,6 +36,8 @@ int main(int argc, char *argv[])
mosquitto_loop(mosq, -1, 1);
}
mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
return run;
}

View File

@ -28,6 +28,7 @@ int main(int argc, char *argv[])
mosquitto_loop(mosq, -1, 1);
}
mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
return run;
}