Fix some defects discovered by coverity.
This commit is contained in:
parent
70f2bea51f
commit
37dceb38f9
@ -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"
|
||||
|
@ -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]);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -36,6 +36,8 @@ int main(int argc, char *argv[])
|
||||
mosquitto_loop(mosq, -1, 1);
|
||||
}
|
||||
|
||||
mosquitto_destroy(mosq);
|
||||
|
||||
mosquitto_lib_cleanup();
|
||||
return run;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ int main(int argc, char *argv[])
|
||||
mosquitto_loop(mosq, -1, 1);
|
||||
}
|
||||
|
||||
mosquitto_destroy(mosq);
|
||||
mosquitto_lib_cleanup();
|
||||
return run;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user