Skip to content

Commit

Permalink
config.c: Remove superfluous file open.
Browse files Browse the repository at this point in the history
The current config file is opened before we begin the process
of reading it and copying over its contents in order to update
or insert a new configuration value, but this opened file is
never used, simply closed after this process completes. I
probably wrote it this way with the assumption the copy process
uses this file handle, but it doesn't; it opens its own. Therefore,
this file was opened and closed for no reason, and this code can
simply be removed. Doing so also seems to prevent this from being
leaked.
  • Loading branch information
InterLinked1 committed Dec 26, 2024
1 parent e7b63f3 commit 1f16af5
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions bbs/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ static struct bbs_config *config_parse(const char *name)

int bbs_config_set_keyval(const char *filename, const char *section, const char *key, const char *value)
{
FILE *oldfp, *newfp;
FILE *newfp;
struct bbs_config *cfg;
size_t fsize;
struct stat st;
Expand All @@ -558,23 +558,15 @@ int bbs_config_set_keyval(const char *filename, const char *section, const char
* (and may not know or care what the old value is).
* So, do a brute force copy and update/add/replace. */

oldfp = fopen(filename, "r");
if (!oldfp) {
bbs_warning("Existing config file '%s' does not exist\n", filename);
/* If config file doesn't exist, we could create it,
* but more than likely something is wrong and we should just abort. */
return -1;
}
newfp = bbs_mkftemp(tmpfile, 0660);
if (!newfp) {
fclose(oldfp);
return -1;
}

cfg = config_parse_or_write(filename, &newfp, section, key, value);

/* Finalize and cleanup */
fclose(oldfp);

if (!newfp) {
/* Failure occured, and newfp has already been closed. */
if (cfg) {
Expand Down

0 comments on commit 1f16af5

Please sign in to comment.