Remove unnecessary uses of calloc.

pull/211/merge
Roger A. Light 11 years ago
parent 30c83a5cc1
commit 97849e8825

@ -1074,12 +1074,13 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
do{
len = strlen(token)+1+strlen(find_data.cFileName)+1;
conf_file = _mosquitto_calloc(len+1, sizeof(char));
conf_file = _mosquitto_malloc(len+1);
if(!conf_file){
FindClose(fh);
return MOSQ_ERR_NOMEM;
}
snprintf(conf_file, len, "%s\\%s", token, find_data.cFileName);
conf_file[len] = '\0';
rc = _config_read_file(config, reload, conf_file, cr, level+1, &lineno_ext);
if(rc){
@ -1102,12 +1103,13 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(strlen(de->d_name) > 5){
if(!strcmp(&de->d_name[strlen(de->d_name)-5], ".conf")){
len = strlen(token)+1+strlen(de->d_name)+1;
conf_file = _mosquitto_calloc(len+1, sizeof(char));
conf_file = _mosquitto_malloc(len+1);
if(!conf_file){
closedir(dh);
return MOSQ_ERR_NOMEM;
}
snprintf(conf_file, len, "%s/%s", token, de->d_name);
conf_file[len] = '\0';
rc = _config_read_file(config, reload, conf_file, cr, level+1, &lineno_ext);
if(rc){
@ -1757,12 +1759,13 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(cur_topic->local_prefix){
if(cur_topic->topic){
len = strlen(cur_topic->topic) + strlen(cur_topic->local_prefix)+1;
cur_topic->local_topic = _mosquitto_calloc(len+1, sizeof(char));
cur_topic->local_topic = _mosquitto_malloc(len+1);
if(!cur_topic->local_topic){
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory");
return MOSQ_ERR_NOMEM;
}
snprintf(cur_topic->local_topic, len+1, "%s%s", cur_topic->local_prefix, cur_topic->topic);
cur_topic->local_topic[len] = '\0';
}else{
cur_topic->local_topic = _mosquitto_strdup(cur_topic->local_prefix);
if(!cur_topic->local_topic){
@ -1781,12 +1784,13 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(cur_topic->remote_prefix){
if(cur_topic->topic){
len = strlen(cur_topic->topic) + strlen(cur_topic->remote_prefix)+1;
cur_topic->remote_topic = _mosquitto_calloc(len+1, sizeof(char));
cur_topic->remote_topic = _mosquitto_malloc(len+1);
if(!cur_topic->remote_topic){
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory");
return MOSQ_ERR_NOMEM;
}
snprintf(cur_topic->remote_topic, len, "%s%s", cur_topic->remote_prefix, cur_topic->topic);
cur_topic->remote_topic[len] = '\0';
}else{
cur_topic->remote_topic = _mosquitto_strdup(cur_topic->remote_prefix);
if(!cur_topic->remote_topic){

@ -56,7 +56,7 @@ int base64_encode(unsigned char *in, unsigned int in_len, char **encoded)
return 1;
}
BIO_get_mem_ptr(b64, &bptr);
*encoded = calloc(bptr->length+1, 1);
*encoded = malloc(bptr->length+1);
if(!(*encoded)){
BIO_free_all(b64);
return 1;

@ -342,12 +342,13 @@ int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown)
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Saving in-memory database to %s.", db->config->persistence_filepath);
len = strlen(db->config->persistence_filepath)+5;
outfile = _mosquitto_calloc(len+1, 1);
outfile = _mosquitto_malloc(len+1);
if(!outfile){
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, out of memory.");
return MOSQ_ERR_NOMEM;
}
snprintf(outfile, len, "%s.new", db->config->persistence_filepath);
outfile[len] = '\0';
db_fptr = _mosquitto_fopen(outfile, "wb");
if(db_fptr == NULL){
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, unable to open %s for writing.", outfile);
@ -479,7 +480,7 @@ static int _db_client_chunk_restore(struct mosquitto_db *db, FILE *db_fptr)
if(db_version == 2){
disconnect_t = time(NULL);
}else{
read_e(db_fptr, &disconnect_t, sizeof(time_t));
read_e(db_fptr, &disconnect_t, sizeof(uint32_t));
}
context = _db_find_or_add_context(db, client_id, last_mid);

@ -191,7 +191,7 @@ int mqtt3_handle_publish(struct mosquitto_db *db, struct mosquitto *context)
_mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Dropped too large PUBLISH from %s (d%d, q%d, r%d, m%d, '%s', ... (%ld bytes))", context->id, dup, qos, retain, mid, topic, (long)payloadlen);
goto process_bad_message;
}
payload = _mosquitto_calloc(payloadlen+1, sizeof(uint8_t));
payload = _mosquitto_malloc(payloadlen+1);
if(!payload){
_mosquitto_free(topic);
return 1;
@ -201,6 +201,7 @@ int mqtt3_handle_publish(struct mosquitto_db *db, struct mosquitto *context)
_mosquitto_free(payload);
return 1;
}
payload[payloadlen] = '\0';
}
/* Check for topic access */

Loading…
Cancel
Save