Simplify some error states

pull/2345/merge
Roger A. Light 3 years ago
parent 907b754566
commit 677aa2cc8d

@ -147,7 +147,6 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
int l_file_count = 0;
char **files_tmp;
size_t len;
int i;
DIR *dh;
struct dirent *de;
@ -164,25 +163,11 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
l_file_count++;
files_tmp = mosquitto__realloc(l_files, (size_t)l_file_count*sizeof(char *));
if(!files_tmp){
for(i=0; i<l_file_count-1; i++){
mosquitto__FREE(l_files[i]);
}
mosquitto__FREE(l_files);
closedir(dh);
return MOSQ_ERR_NOMEM;
}
if(!files_tmp) goto error;
l_files = files_tmp;
l_files[l_file_count-1] = mosquitto__malloc(len+1);
if(!l_files[l_file_count-1]){
for(i=0; i<l_file_count-1; i++){
mosquitto__FREE(l_files[i]);
}
mosquitto__FREE(l_files);
closedir(dh);
return MOSQ_ERR_NOMEM;
}
if(!l_files[l_file_count-1]) goto error;
snprintf(l_files[l_file_count-1], len, "%s/%s", include_dir, de->d_name);
l_files[l_file_count-1][len] = '\0';
}
@ -197,6 +182,13 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
*file_count = l_file_count;
return 0;
error:
for(int i=0; i<l_file_count-1; i++){
mosquitto__FREE(l_files[i]);
}
mosquitto__FREE(l_files);
closedir(dh);
return MOSQ_ERR_NOMEM;
}
#endif

@ -40,34 +40,27 @@ int send__auth(struct mosquitto *context, uint8_t reason_code, const void *auth_
remaining_length = 1;
rc = mosquitto_property_add_string(&properties, MQTT_PROP_AUTHENTICATION_METHOD, context->auth_method);
if(rc){
mosquitto_property_free_all(&properties);
return rc;
}
if(rc) goto error;
if(auth_data != NULL && auth_data_len > 0){
rc = mosquitto_property_add_binary(&properties, MQTT_PROP_AUTHENTICATION_DATA, auth_data, auth_data_len);
if(rc){
mosquitto_property_free_all(&properties);
return rc;
}
if(rc) goto error;
}
remaining_length += property__get_remaining_length(properties);
if(packet__check_oversize(context, remaining_length)){
mosquitto_property_free_all(&properties);
return MOSQ_ERR_OVERSIZE_PACKET;
}
rc = packet__check_oversize(context, remaining_length);
if(rc) goto error;
rc = packet__alloc(&packet, CMD_AUTH, remaining_length);
if(rc){
mosquitto_property_free_all(&properties);
return rc;
}
if(rc) goto error;
packet__write_byte(packet, reason_code);
property__write_all(packet, properties, true);
mosquitto_property_free_all(&properties);
return packet__queue(context, packet);
error:
mosquitto_property_free_all(&properties);
return rc;
}

Loading…
Cancel
Save