summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorAlain Vongsouvanh <alainv@google.com>2015-12-09 08:57:38 -0800
committerAndre Eisenbach <eisenbach@google.com>2015-12-09 22:59:02 +0000
commited2267a0a66b1aec52d9039bc20a6c5099dbdae7 (patch)
treeaf14fc5dbb445a17c0268ecdd1b93bf0a120a8b0 /osi
parent865e736eea16629fcbb24aea18b250a0f51b31c7 (diff)
downloadandroid-system-bt-ed2267a0a66b1aec52d9039bc20a6c5099dbdae7.tar.gz
android-system-bt-ed2267a0a66b1aec52d9039bc20a6c5099dbdae7.tar.xz
osi: Remove error_fclose goto and redundant fflush.
Change-Id: I327f9ce696bb68eb3b89b4a8b15dba189e027970
Diffstat (limited to 'osi')
-rw-r--r--osi/src/config.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/osi/src/config.c b/osi/src/config.c
index f5d24d3..bf753e7 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -272,14 +272,14 @@ bool config_save(const config_t *config, const char *filename) {
const section_t *section = (const section_t *)list_node(node);
if (fprintf(fp, "[%s]\n", section->name) < 0) {
LOG_ERROR(LOG_TAG, "%s unable to write to file '%s': %s", __func__, temp_filename, strerror(errno));
- goto error_fclose;
+ goto error;
}
for (const list_node_t *enode = list_begin(section->entries); enode != list_end(section->entries); enode = list_next(enode)) {
const entry_t *entry = (const entry_t *)list_node(enode);
if (fprintf(fp, "%s = %s\n", entry->key, entry->value) < 0) {
LOG_ERROR(LOG_TAG, "%s unable to write to file '%s': %s", __func__, temp_filename, strerror(errno));
- goto error_fclose;
+ goto error;
}
}
@@ -287,21 +287,17 @@ bool config_save(const config_t *config, const char *filename) {
if (list_next(node) != list_end(config->sections)) {
if (fputc('\n', fp) == EOF) {
LOG_ERROR(LOG_TAG, "%s unable to write to file '%s': %s", __func__, temp_filename, strerror(errno));
- goto error_fclose;
+ goto error;
}
}
}
- if (fflush(fp) == EOF) {
- LOG_ERROR(LOG_TAG, "%s unable to flush to file '%s': %s", __func__, temp_filename, strerror(errno));
- goto error_fclose;
- }
-
if (fclose(fp) == EOF) {
LOG_ERROR(LOG_TAG, "%s unable to close file '%s': %s", __func__, temp_filename, strerror(errno));
- // Calling fclose now has undefined behavior so skip calling it again and jump to 'error' instead.
+ fp = NULL;
goto error;
}
+ fp = NULL;
// Change the file's permissions to Read/Write by User and Group
if (chmod(temp_filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1) {
@@ -317,9 +313,9 @@ bool config_save(const config_t *config, const char *filename) {
osi_free(temp_filename);
return true;
-error_fclose:;
- fclose(fp);
error:;
+ if (fp != NULL)
+ fclose(fp);
unlink(temp_filename);
osi_free(temp_filename);
return false;